for i in driver.find_elements_by_class_name("endorse-count"): try: i.click() except: continue elem = WebDriverWait(driver, 100).until(EC.presence_of_element_located((By.CLASS_NAME, "dialog-window"))) src = elem.get_attribute("innerHTML") add_skill(name, src) WebDriverWait(driver, timeout=10)
When executing the above code, the following error appears:
selenium.common.exceptions.StaleElementReferenceException: Message: u'Element is no longer attached to the DOM' ; Stacktrace: at fxdriver.cache.getElementAt (resource://fxdriver/modules/web_element_cache.js:7646)
for string -
src = elem.get_attribute("innerHTML")
I run this code on the LinkedIn user profile page after logging in.
I tried to put the next line of code after "i.click ()" -
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
But then I see that the function "add_skill (name, src)" is not called and none of the code is executed after calling driver.manage (), although i.click () works fine for the loop and on.
python dom exception-handling selenium selenium-webdriver
theharshest
source share