Simple noobie XPath question

Ask general questions here.
sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Simple noobie XPath question

Post by sstowe » Fri Jun 01, 2018 8:15 pm

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Simple noobie XPath question

Post by odklizec » Sat Jun 02, 2018 9:46 am

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']
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: Simple noobie XPath question

Post by sstowe » Mon Jun 04, 2018 9:27 pm

Lovely. I was able to use your post fix my immediate issue as well as google some more topics. Thank you.

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: Simple noobie XPath question

Post by sstowe » Tue Jun 12, 2018 3:24 pm

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!

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: Simple noobie XPath question

Post by sstowe » Tue Jun 12, 2018 4:14 pm

Ha! Ask on forum... and you will figure it out! I am all set.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Simple noobie XPath question

Post by odklizec » Wed Jun 13, 2018 8:44 am

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: Simple noobie XPath question

Post by sstowe » Wed Jun 13, 2018 1:20 pm

Thanks, thanks, thanks. That is just what I needed. I am just realizing the benefit of snapshots. (See? Noob!)