I want to click on the following element "23 verkauft" on an eBay productpage you can see it on this screenshot:
Here is the HTMl Code of this Element:
Here is my Code but the webdriver cant locate the element or can’t click on it.
sold = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//span[@class, 'vi-txt-underline']")))
sold.click()
2
Answers
You have an error with your locator.
Instead of
It should be
Also instead of
presence_of_element_located
you should usevisibility_of_element_located
since the former method will wait for more mature element state, not only presented on the page but also visible.Also you can click on the element there directly, no need for the additional code line.
So your code could be
You were close enough. But you have to make to adjustments:
(By.XPATH, "//span[@class, 'vi-txt-underline']")
you need to use(By.XPATH, "//span[@class='vi-txt-underline']")
Solution
To click on the element with text as 23 verkauft you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using LINK_TEXT:
Using CSS_SELECTOR:
Using XPATH:
Note: You have to add the following imports :