1

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.

3
  • What's the task you're automating? Maybe it got stuck in a loop in certain cases? Or, maybe the connection to the site the for which you're automating the task times out after a while? It's hard to know without more context I think. Commented Oct 3, 2019 at 8:53
  • I want to know your browser settings. Try to add this: browser.maximize_window() Commented Oct 3, 2019 at 9:22
  • @Yun ` chrome_options=Options() chrome_options.add_experimental_option('excludeSwitches',['enable-automation']) chrome_options.add_argument("--log-level=3") prefs = {"profile.managed_default_content_settings.images": 2} chrome_options.add_experimental_option("prefs", prefs) chrome_options.add_argument('--headless') browser = webdriver.Chrome(chrome_options=chrome_options) browser.set_window_size(1920,1080) ` `` these are my settings, and i find "browser.maximize_window()" don't work in headless mode, so I use the "set_window_size(1920,1080)". Commented Oct 3, 2019 at 9:34

1 Answer 1

1

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:

  • Selenium client version
  • ChromeDriver version
  • Relevant HTML DOM

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this is a total guess

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.