Xpath change broke automation

Ask general questions here.
AviatorFly
Posts: 13
Joined: Fri Sep 06, 2019 2:21 pm

Xpath change broke automation

Post by AviatorFly » Tue Feb 11, 2020 4:00 pm

Hi,


I am fairly new still and I am coming back to use Ranorex after a few months break. My existing code was looking for a username entry box that had the xpath set to:

.//div[#'app']/div/div/div[2]//form[@action='http://SomeMachine/login']/div[1]/div[1]/div/div[1]/?/?/input[@name='username']

After I ran it, it could not find the username entry box anymore. I used the spy tool and noticed that the xpath is now:

.//div[#'app']/div/main/div/div/div/div[2]//form[@action='http://SomeMachine/login']/div[1]/div[1]/div/div[1]/?/?/input[@name='username']

Is there someway I can make this more robust so that it could still find it? Is there a way to reference by name instead of the xpath?

Thanks

R

User avatar
Support Team
Site Admin
Site Admin
Posts: 12161
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Xpath change broke automation

Post by Support Team » Tue Feb 11, 2020 10:36 pm

Hi AviatorFly,

It appears there may be some dynamic elements in the AUT that change the structure of the application, and therefore break the RxPath to this element. The easiest solution to this is to remove all the differences between the two RxPaths. The below RxPath will work in both scenarios:

Code: Select all

.//div[#'app']/div//form[@action='http://SomeMachine/login']/div[1]/div[1]/div/div[1]/?/?/input[@name='username']
If we want to be extra robust, we can use the below, however this can cause a decrease in performance and may cause Ranorex to find the wrong element if there is more than one input with the name 'username'.

Code: Select all

.//div[#'app']//form[@action='http://SomeMachine/login']//input[@name='username']
For more information on handling dynamic content, check out this user guide page and blog post.

Also, in the newest versions of Ranorex, you can edit the RanoreXPath settings to generate a more robust RxPaths by default when adding a new element so that you do not need to manually edit them to be robust.
1.png
1.png (26.16 KiB) Viewed 179 times
I hope this helps!

Regards,
Ned
.
Image