skip to Main Content

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()

2

Answers


  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()
    
    Login or Signup to reply.
  2. 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
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search