I have elements on my application that have long xPaths such as:
element[@class='QWidget' and @instance='3']/element[@class='QWidget' and @instance='0']/element[@class='QWidget' and @instance='1']/element[@class='QWidget' and @instance='0']/element[@class='QWidget' and @instance='2']/element[@class='QWidget' and @instance='0']/element[@class='QWidget' and @instance='0']/element/element[@class='QWidget' and @instance='1']/element[@class='QWidget' and @instance='4']/button[@accessiblename='Save Image']
In the above case the path is to a button named 'Save Image'. The problem is that the instance numbers can change dynamically depending on how many elements are configured in the application for that form. So often times if I cannot reuse scripts that I record if I restart the application.
Since in the above example 'accessiblename' is a unique identifier for this button element I tried to modify the xPath to "element[@class='QWidget']/button[@accessiblename='Save Image']" but Ranorex then could no longer identify the object.
Since the accessiblename for this element is unique shouldn't I be able to just use class and accessiblename in the xPath? Thanks
Problem Modifying xPath
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Problem Modifying xPath
Hi costamesakid!
Use // instead to check all descendants from an given object path.
So element[@class='QWidget']//button[@accessiblename='Save Image'] should work.
Also see the userguide for more information how to use RxPath: http://www.ranorex.com/support/user-gui ... xpath.html
Best regards,
Christian
Ranorex Team
Use // instead to check all descendants from an given object path.
So element[@class='QWidget']//button[@accessiblename='Save Image'] should work.
Also see the userguide for more information how to use RxPath: http://www.ranorex.com/support/user-gui ... xpath.html
Best regards,
Christian
Ranorex Team
-
- Posts: 94
- Joined: Tue Jun 16, 2009 10:27 pm
Re: Problem Modifying xPath
That worked great! Thanks
Hit another snag though and I cannot find the solution in the Users Guide. How do I reference an object via xPath that has the same accessiblename as another object on a form. For instance I have 2 links with the same name:
element[@class='QWidget']//text[@accessiblename='Start']
element[@class='QWidget']//text[@accessiblename='Start']
Hit another snag though and I cannot find the solution in the Users Guide. How do I reference an object via xPath that has the same accessiblename as another object on a form. For instance I have 2 links with the same name:
element[@class='QWidget']//text[@accessiblename='Start']
element[@class='QWidget']//text[@accessiblename='Start']
Re: Problem Modifying xPath
Are the objects differentiable by another property other than accessiblename?
If both objects are truly children of the same element then they are probably differentiated by index, which is determined at runtime of the AUT.
If that is the case you can work out some custom code that has logic in it to determine which one you want to click. Or you should add a property differentiator in the xPath string.
If both objects are truly children of the same element then they are probably differentiated by index, which is determined at runtime of the AUT.
If that is the case you can work out some custom code that has logic in it to determine which one you want to click. Or you should add a property differentiator in the xPath string.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Problem Modifying xPath
As ciege said, you can use the index to differentiate the two elements. You can do that using custom code or in the RxPath (note that indexes in XPath are one-based):
First element: element[@class='QWidget']//text[@accessiblename='Start'][1]
Second element: element[@class='QWidget']//text[@accessiblename='Start'][2]
Regards,
Alex
Ranorex Support Team
First element: element[@class='QWidget']//text[@accessiblename='Start'][1]
Second element: element[@class='QWidget']//text[@accessiblename='Start'][2]
Regards,
Alex
Ranorex Support Team
-
- Posts: 94
- Joined: Tue Jun 16, 2009 10:27 pm
Re: Problem Modifying xPath
This is interesting. I modified my xPaths to:
First element: element[@class='QWidget']//text[@accessiblename='Start'][1]
Second element: element[@class='QWidget']//text[@accessiblename='Start'][2]
In the repository I clicked 'Highlight Element' for each entry. As expected the 1st entry highlighted the 1st occurrence of the 'Start' link and the 2nd entry highlighted the 2nd occurrence of the 'Start' link. However, when I played back the script Ranorex clicked on the 1st occurrence of the 'Start' link 2 times.
Any ideas on why this would happen? Thanks
First element: element[@class='QWidget']//text[@accessiblename='Start'][1]
Second element: element[@class='QWidget']//text[@accessiblename='Start'][2]
In the repository I clicked 'Highlight Element' for each entry. As expected the 1st entry highlighted the 1st occurrence of the 'Start' link and the 2nd entry highlighted the 2nd occurrence of the 'Start' link. However, when I played back the script Ranorex clicked on the 1st occurrence of the 'Start' link 2 times.
Any ideas on why this would happen? Thanks
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Problem Modifying xPath
Actually, no, if it works in Ranorex Spy, it should work in code, too - both use the same Ranorex library methods. Please, check that you use the RanoreXPaths in your code or in your repository, respectively!costamesakid wrote:Any ideas on why this would happen?
Regards,
Alex
Ranorex Support Team
-
- Posts: 94
- Joined: Tue Jun 16, 2009 10:27 pm
Re: Problem Modifying xPath
Actually, there have been a few incidents of this happening from programmers/tester here and we have it well documented now so we have scheduled a Web Cast with Support/Development. I will post the results of said meeting. Thanks