Search code examples
pythonseleniumweb-scrapingwebdriver

Python Selenium get "sold items" information from eBay Productpage


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

Solution

  • 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