18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
How to get the last element?
I am testing a Web 2.0 application. There is a dialogue implemented by DIV in the page. Everytime the dialogue pops up, a new DIV is created. So the first time, I can get the dialogue by "div('my dialogue title')" but the second time I have to use "div('my dialogue title[1]')" then the third time "div('my dialogue title[2]')". Certainly this might be a development problem -- they should destroy the previous DIV object, but is there any good way to let me always get the last element in the array? If so I do fail at such kind of case any more. Say, "div(my dialogue title[-1])" -- in Python, we can use the index -1 to get the last element in the array.
This discussion has been closed.
Comments
You can first get the count of div using _count() API.
For more details:
http://blog.sahi.co.in/search?q=_count
Then,you can use: _div("title[" + count-1 +"]");
Regards
Sumitra