Reputation: 255
please help me. Actually I want to find element locator in selenium using XPath since the id is auto-generate (the ID always changed when the page refresh). but the XPath always changed too. here is the XPath locator :
html/body/div[4]/div/div[1]/div/table[1]/tbody[2]/tr[1]/td/div/nobr
html/body/div[4]/div/div[1]/div/table[1]/tbody[2]/tr[1]/td/div/nobr
html/body/div[15]/div/div[1]/div/table[1]/tbody[2]/tr[1]/td/div/nobr
html/body/div[7]/div/div[1]/div/table[1]/tbody[2]/tr[1]/td/div/nobr
Actually I already try to use :
html/body/div[class='scrollingMenu']/div/div[1]/div/table[1]/tbody[2]/tr[1]/td/div/nobr
the div itself has unique classname scrollingMenu. but it is not working. it always give the error element not found.
Upvotes: 0
Views: 260
Reputation: 52675
You can use element's id
in your XPath
as follow:
Suppose id="constantPart-generatedPart12345"
, then XPath
is
//*[contains(@id, "constantPart-")]
PS. If this not works, update your question with HTML
for target element, so I can edit XPath
appropriatelly
Upvotes: 0
Reputation: 11
Open the page in Google Chrome and use F12 to test your xPath before implementing it - has saved me a lot of time
Upvotes: 0