RE: xpath regular expression

Hi ..when i use fire path I get the xpath first time as -“//*[@id=’preMatrix’]/div[3]/div[2]/span” and if i refresh page the xpath changes to -“//*[@id=’preMatrix’]/div[4]/div[2]/span” do I genaralise this using regular expression .Pls help

PK Default Asked on April 17, 2015 in Selenium WebDriver.
Add Comment
1 Answers

The best way to answer this would be to see the html of the element.  Ideally there are many ways to find the element.
– The problem here seems that you have new element which is introduced dynamically in the DOM and above your target element. I would prefer to find the amount of time it takes for the new element to come, wait for that much amount of time and then find this element with second Xpath you have mentioned.

– Second way is that this element will have a fixed position from the bottom of the array of similar elements. //*[@id=’preMatrix’] will have lots of Divs find the last div and see if you element changes position based on the last element. If it does not you are looking at an xpath like this
“//*[@id=’preMatrix’]/div[last()- x]/div[2]/span”. where x is the position of the target element from the last element of same type.


Professor Answered on April 17, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.