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()
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']")
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:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "23 verkauft"))).click()
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.vi-txt-underline"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='23 verkauft']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC