0

I'm using Scrapy and Selenium, and keep getting this "Element is no longer attached to the DOM” error. I looked and I realize I'm supposed to have wait period until element loads. However I tried many ways, and still doesn't seem to work. First time using Selenium here, so maybe I'm missing an obvious. Snippet of the code below:

elements=self.driver.find_elements(By.XPATH, 
  '//*[(@id = "ContentPlaceHolder1_UPProducts")]//*[contains(concat( " ", @class, " " ), concat( " ", "pb-2", " " ))]')

for element in elements:
  ignored_exceptions=(NoSuchElementException,StaleElementReferenceException)
  title = WebDriverWait(element, 5,ignored_exceptions=ignored_exceptions).until(expected_conditions.presence_of_element_located((By.CLASS_NAME, 'pl-3'))).text

When I run this, I get error at this line

    elements = WebDriverWait(sound, 5,ignored_exceptions=ignored_exceptions).until(expected_conditions.presence_of_element_located((By.CLASS_NAME, 'pl-3'))).text
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

Does the code make sense? Can I use the element in place of the driver here when calling WebDriverWait?

Bashar Abdullah
  • 1,545
  • 1
  • 16
  • 27

0 Answers0