Selenium with headless chrome fails to get url when switching tabs
Asked Answered
P

2

7

I'm currently running Selenium with Specflow.

One of my tests clicks on a button which triggers the download of a pdf file. That file is automatically opened in a new tab where the test then grabs the url and downloads the referenced file directly to the selenium project. This whole process works perfectly when chrome driver is run normally but fails on a headless browser with the following error:

The HTTP request to the remote WebDriver server for URL http://localhost:59658/session/c72cd9679ae5f713a6c857b80c3515e4/url timed out after 60 seconds. -> The request was aborted: The operation has timed out.

This error occurs when attempting to run driver.Url

driver.Url calls work elsewhere in the code. It only fails after the headless browser switches tabs. (Yes, I am switching windows using the driver)

For reference, I cannot get this url without clicking the button on the first page and switching tabs as the url is auto-generated after the button is clicked.

Paver answered 8/8, 2018 at 19:14 Comment(2)
I am also having this issue, did you ever find a solution?Gut
I also want to know if you found the solution as I am experiencing the same in 2022...Melanosis
C
0

I believe you are just using argument as "--headless" for better performance you should select screen size too. Sometimes, due to inappropriate screen size it cannot detect functions which you are looking for. try using this code or just add one line for size.

from selenium import webdriver
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
driver = webdriver.Chrome(chrome_options=chrome_options)

Don't forget to put other arguments according to your need in "driver".

Cohabit answered 10/12, 2020 at 18:25 Comment(0)
F
0

try using this headless argument instead: "--headless=new"

Firebox answered 20/12, 2023 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.