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 number of elements

zakka.fauzanzakka.fauzan Members
edited July 2013 in Sahi - Open Source
let's say I access my <span> elements using
_span({className:"amount"})
However, I have a lot of span having class name amount. How to get the 2nd, 3rd, etc elements?

Answers

  • Hi zakka,
    You can access the 2nd, 3rd elements using positional APIs like _near, _in, _under etc. They can be identified with reference to known elements around them in DOM structure.
    You can find the details on the following link.
    http://sahi.co.in/w/browser-accessor-apis
    

    If there is visible text for the span you want to access,
    you can also try using:
    _span({className:"amount",sahiText:"<visible_text>"})
    

    Regards.
  • The thing is, I don't know what'll be around those 2nd, 3rd elements... and I don't know what's the text (that's what I wanna get actually).
  • Hi,
    You can access the spans using the following code:
    for the first span: _span("amount[0]")
    for the second span: _span("amount[1]")
    for the third span: _span("amount[2]")
    and so on..
    

    Regards.
  • I just know that we can use class also there... Thank you!
  • Hi,
    If you're unaware of the text around the elements, you can use the code in my first reply, as it doesn't require prior knowledge of the surrounding text.

    Regards.
Sign In or Register to comment.