Page 1 of 1

How to write a regular expression for changing index

Posted: Thu Sep 28, 2017 12:50 am
by RekhaG
Hello there,

I am validating on logo of the website, but the index of the dom keeps changing which is causing my test case to fail. Can some one tell how to write a regular expression for a changing index. I browsed through the examples of regular expression in your website but could not find an appropriate solution for my problem.

Example Xpath: /dom[11]//div[#'headleft']?/?/img[@alt='Bio-Rad logo']

In the above example dom[11] might become dom[5] and so on. How can i avoid this problemt

Re: How to write a regular expression for changing index

Posted: Thu Sep 28, 2017 7:00 am
by odklizec
Hi,

I think that using regex for index number in DOM is useless. You can the same remove the index completely from the xpath:

Code: Select all

/dom//div[#'headleft']?/?/img[@alt='Bio-Rad logo']
What you should do is to add a meaningful attribute to the xpath, like @domain. Otherwise, the search for elements could take a lot of time, because there could be numerous DOMs and Ranorex will have to search them all, until it finds matching element. So in my opinion, it's critical to set a meaningful attribute for DOM element.

Re: How to write a regular expression for changing index

Posted: Thu Sep 28, 2017 6:19 pm
by RekhaG
Thank you so much odklizec!! After removing the index it worked fine