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
--
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.