Reputation: 11
When I use selenium to automate, I find sometimes I will get the Exception:
Message: timeout (Session info: headless chrome=77.0.3865.90)
and I don't know what happened.
I tried to Google but I couldn't find the reason.
try:
li.click()
browser.find_element_by_xpath('//div[@class="user-info"]/div[@class="user-info-detail"]/a').get_attribute('href')
except Exception as e:
print(e)
"Message: timeout (Session info: headless chrome=77.0.3865.50)", sometimes I will get the exception but in general it won't.
Upvotes: 1
Views: 2596
Reputation: 193078
This error message...
Message: timeout (Session info: headless chrome=77.0.3865.50)
...implies that the ChromeDriver instance timed out while attempting to locate the desired element rendered through headless chrome=77.0.
A bit of more information with respect to:
would have helped us to debug the issue in a better way.
However, possibly the element exists but the href attribute was not rendered within the DOM Tree. As your usecase is to retrieve the href attribute of an WebElement, ideally you need to induce WebDriverWait for the visibility_of_element_located()
. So your effective code block will be as follows:
try:
print(WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='user-info']/div[@class='user-info-detail']/a"))).get_attribute("title"))
except Exception as e:
print(e)
Inducing WebDriverWait along with ExpectedConditions wouldn't through the raw message on the console.
Upvotes: 1