1

I am trying to scrape some Target product information and am running into an issue trying to reference the UPC digits.

I am using Selenium on Python and am trying to reference the UPC and the digits, but there doesn't seem to be a way to reference the digits portion of it. I am currently trying:

UPC = driver.find_element_by_xpath("//*[text()[contains(.,'UPC')]]")

But this only returns the string 'UPC' and not the digits.

Does anyone know how to reference the entire element? I posted some images along with this, thank you!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To scrape the target product information element you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH:

    UPC = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*[contains(., 'UPC')]")))
    
  • 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