Can Someone Please Explain Me How To Write An Xpath For Selenium On Python?
Solution 1:
Here you can find a good tutorial, which will teach you xPath basics. On the webpage when you press F12
the dev tools opens:
Then you click on one of the elemnts and then Ctrl+f
. Then the search menu will open:
There you can type xPaths and CSS Selectors to make sure, that you have found the right element. For example:
once you have typed yor xPath , you will see on the right side the number of the elements found, also you can click on up
and down
buttons to iterate over every element, to see whic exactly element is on number 1,2...
Once you have found the right xPath, just copy it from dev tools and paste in the code like this:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div"))).click()
In this case it will be selected only one element. If you want to wait until all elements, if there are more than 1, just use one of the EC
methods, for example:
WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div")))
this will wait for visibility of all elements located by //div
xPath.
Hope this helps.
Post a Comment for "Can Someone Please Explain Me How To Write An Xpath For Selenium On Python?"