18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Get span by ID

SahiUser59SahiUser59 Members
edited November -1 in Sahi - Open Source
Hi,
I know I can get a textbox by using its ID e.g. _textbox("ShortName") but I am trying to get the span by using its ID.

_span("/7/1/1/")

( yes the Id is /7/1/1 )
The text inside this span matches another one and so I need to use the ID.

So the code will look like this:
var $item2 = _span("/7/1/1/");
_click($item2);

Comments

  • Hi

    please try to escape the ID like _span("\/7\/1\/1\/") so that it isn't recognized as regular expression. Can you access the span with the Sahi controller?

    Regards
    Wormi
  • My question is more general really - how do I get a span by its ID?

    This is the problem: If I have two elements like this:

    <span id="myID1">Hello World</span>
    <span id="myID2">Hello World</span>

    and I want the second span, how do I get it?
    I would want to reference it by _span("myID2"); But I cannot.

    The documentation says I can only use the display text, and _span("Hello World") will return myID1 :(
    _span ( text )
    Returns an HTML element rendered by a span tag displaying a particular text.
  • Obviously I needed to use document.getElementById

    var $item2 = document.getElementById("/7/1/1/");
    _click($item2);

    Sorry for being dim guys, it was really warm in the office yesterday and it was making me feel pretty sleepy ha ha!
Sign In or Register to comment.