How To Handle Dynamically Changing Value With Selenium And Python?
Below is what HTML has. If I click using below XPATH, it's working fine. But data-qtip value keep changing and also there are other class with same name as above in HTML. How can
Solution 1:
based on OP response, there are 9 data-qtip and due to lack of HTML, I will proide you solution using xpath indexing.
(//span[@data-qtip])[1]
should represent the first 1 element, [2] should represent the second element.
(//span[@data-qtip])[2]
and so on..
PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.
You can try to increase the index to have a unique matching node in HTMLDOM.
Code trial 1 :
time.sleep(5)
driver.find_element_by_xpath("(//span[@data-qtip])[1]").click()
Solution 2:
In your DOM if data-qtip is unique attribute then you can use below xPath
xPath:
//span[@data-qtip]
Code:
driver.find_element_by_xpath("//span[@data-qtip]").click()
Post a Comment for "How To Handle Dynamically Changing Value With Selenium And Python?"