Timeout exception while waiting for webpage with element in headless chrome

880 views
Skip to first unread message

Rajesh Singh

unread,
Jun 27, 2019, 11:47:21 AM6/27/19
to Selenium Users

Following code uses non-headless chrome and it works:

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait


chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--start-maximized')
chrome_options.binary_location = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'

driver = webdriver.Chrome(executable_path=os.path.abspath("C:\User\Program Files\chrome-driver\chromedriver.exe"))

driver.set_window_size(1200, 600) 

driver.get("login-url")
driver.find_element_by_id("loginId").send_keys("uname")
driver.find_element_by_id("newPassword").send_keys("pwd")
driver.find_element_by_name("submit-button").click()
driver.set_window_size(1200, 800)
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID,"user-info")))

v = driver.find_element_by_xpath("//tr[4]/td[5]/span").text

print(v)


When I choose to use headless chrome:

driver = webdriver.Chrome(executable_path=os.path.abspath("C:\User\Program Files\chrome-driver\chromedriver.exe"), chrome_options=chrome_options)


It throws following exception:

Traceback (most recent call last):
  File "C:/User/workspaces/pyworkspaces/fin2/venv/process.py", line 28, in <module>
    WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID,"user-info")))
  File "C:\User\workspaces\pyworkspaces\fin2\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 


So it seems to fail on following line, in headless chrome:

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID,"user-info")))


I also triedĀ presence_of_element_located:

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,"user-info")))


But it still givesĀ TimeOutException. Why is it so?

Environment

Running chromedriver from command prompt says version 75.0.3770.90.
Chrome is also of exact same version: Version 75.0.3770.100 (Official Build) (64-bit)
Windows 10 64 bit
Python console of PyCharm shows this: Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32

Ab Dul

unread,
Dec 31, 2020, 4:30:27 AM12/31/20
to Selenium Users
Hi Raj ,

Any luck with this issue ?? I think I face similar issue, any help would be great!

Dhrumil Pathak

unread,
Mar 12, 2021, 3:16:53 AM3/12/21
to Selenium Users
I am also facingĀ  the same issue, can any one help on this ?Ā 

Arvind Sah

unread,
Mar 12, 2021, 12:49:13 PM3/12/21
to seleniu...@googlegroups.com
Hi Dhrumil,

When we try to run the non-headless chrome instance on windows machine (VM's) the default browser size when maximized is different as compare headless chrome instance.

I would recommend printing the window size after setting the window size in both cases of headless/normal mode. I am sure you will be able to figure out the issue.Ā 

//Command to print the window size in JAVA
getDriver().manage().window().getSize();

Thanks and Regards,
Arvind Sah

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0fcc8b36-9958-4831-be73-5ddd4ad5da5dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages