pythonseleniumselenium-chromedrivergoogle-chrome-headlessvds

Timeout exception with Selenium in Headless mode


I create driver by:

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('headless')
options.add_argument('disable-infobars')
options.add_argument('--remote-debugging-port=9222')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-notifications")
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome(executable_path='down/chromedriver.exe',chrome_options=options)

After using:

driver.get('https://myip.ru/')
r=WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,'//*[@id="ipcontent"]/table/tbody/tr[2]/td'))).text
print(r)

I get:

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "twitter.py", line 220, in main
    r=WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,'//*[@id="ipcontent"]/table/tbody/tr[2]/td'))).text
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

But it works fine without headless mode

I am also trying to start it on vds and use proxy login by ip.


Solution

  • You already got an answer but I found this: options.add_argument("--headless=new") and it worked for me.