Page 1 of 1

Simple noobie XPath question

Posted: Fri Jun 01, 2018 8:15 pm
by sstowe
I am writing automation for a web application. I am not a noobie to automation but somewhat so to Ranorex. The application under test has elements that are generated at runtime so their containers look different.

/dom[@domain='6012-sbx.btbanking.com']//div[#'dashboard-region-430']/div/div/div[1]/?/?/a[@title='Open Widget Menu']

So here you are seeing the Path for something I want to click on. I don't really care which of these on the screen are found. I want to find the first regardless if the value generated for the Div and click on it.

Can someone help me? Please feel free to correct my terminology or point me to the correct path learning material. Thanks.

Stephanie

Re: Simple noobie XPath question

Posted: Sat Jun 02, 2018 9:46 am
by odklizec
Hi,

The solution of your problem is to replace unique ID with normal ID and regular expression, like this...

Code: Select all

/dom[@domain='6012-sbx.btbanking.com']//div[@id~'dashboard-region']/div/div/div[1]/?/?/a[@title='Open Widget Menu']

Re: Simple noobie XPath question

Posted: Mon Jun 04, 2018 9:27 pm
by sstowe
Lovely. I was able to use your post fix my immediate issue as well as google some more topics. Thank you.

Re: Simple noobie XPath question

Posted: Tue Jun 12, 2018 3:24 pm
by sstowe
So now I wonder what resources there are for learning XPath from the perspective of a Ranorex tester (website consumer)? Rather than write a post for each XPath question, how do I learn to make a stable repo for objects that are different at runtime? For this example

.//div[@id~'dashboard-region']/div/div/div[1]/div/menu/div/li[2]//span[@innertext='Remove']

This refers to to a pop up menu. Sometimes the li shown here is 1 and sometimes 2. I would like the repo to find it regardless.... Thanks!

Re: Simple noobie XPath question

Posted: Tue Jun 12, 2018 4:14 pm
by sstowe
Ha! Ask on forum... and you will figure it out! I am all set.

Re: Simple noobie XPath question

Posted: Wed Jun 13, 2018 8:44 am
by odklizec
Hi,

To learn more about xpaths, I would suggest to start with the screencasts, available here:
https://www.ranorex.com/resources/
Check mainly these:
RanoreXPath and Ranorex Spy
Advanced RanoreXPath manipulation
Ranorex Spy basics
Ranorex Object Repository

Then you should thoroughly read (and understand) the Ranorex User Guide, mainly the parts related to xpaths and spy:
https://www.ranorex.com/help/latest/ranorexpath
https://www.ranorex.com/help/latest/les ... anorex-spy
https://www.ranorex.com/help/latest/ran ... le-library

Then there are blogs:
https://www.ranorex.com/blog/ranorexpat ... roduction/
https://www.ranorex.com/blog/ranorexpat ... nd-tricks/
https://www.ranorex.com/blog/automated- ... namic-ids/

And of course, you need to practice...practice...practice :D

As for the xpath you requested, without seeing the snapshot of the AUT, it's hard to provide a reasonable answer. The thing is, it's relative easy to remove indexes from the xpath and in many cases, the element may still be found without an issue. But in some cases, the xpath without indexes may fail to uniquely identify the element in question. So the simplified xpath may look like this:

Code: Select all

.//div[@id~'dashboard-region']/div//menu/div/li//span[@innertext='Remove']
But you see, without seeing the snapshot, it's hard to tell how stable this xpath would be ;)

The reason why there are used indexes is, that there are most probably no other useful attributes, which may be used for the identification purposes? Hence Ranorex applies indexes in the xpath. But once again, without seeing the snapshot, it's hard to tell more.

Re: Simple noobie XPath question

Posted: Wed Jun 13, 2018 1:20 pm
by sstowe
Thanks, thanks, thanks. That is just what I needed. I am just realizing the benefit of snapshots. (See? Noob!)