1

I want to click on the following element "23 verkauft" on an eBay productpage you can see it on this screenshot:

Element to click on

Here is the HTMl Code of this Element:

HTMl Code

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()
Russgo
  • 104
  • 6

2 Answers2

1

You have an error with your locator.
Instead of

//span[@class, 'vi-txt-underline']

It should be

//a[@class='vi-txt-underline']

Also instead of presence_of_element_located you should use visibility_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

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//a[@class='vi-txt-underline']"))).click()
Prophet
  • 32,350
  • 22
  • 54
  • 79
1

You were close enough. But you have to make to adjustments:


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:

    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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • This was the solution i think. The Webdriver is able to click the element, but then the window closes directly. I could see that the new page was abput to load and then it closed itself. It seemed like a capture would occure on the next page. – Russgo Feb 06 '22 at 16:27