英文:
Selenium Webdriver Headless Mode shows blank page selenium web element
问题
观察:
- 当启用(chrome_linux_headless)时,在单击网页元素后,在Selenium自动化中显示空白页面。
- 如果我禁用Headless模式(Chrome驱动程序),则在Selenium自动化中一切正常。
浏览器详细信息:
Google Chrome 114.0.5735.133(官方版本)(64位)
我们已尝试:
-
driver.navigate().refresh();
-
首先获取浏览器的userAgent:
String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");System.setProperty("useragent", userAgent);
// 将其添加到浏览器选项中,如下所示
options.addArguments("--user-agent=" + System.getProperty("useragent"));
英文:
Observation:
1.When (chrome_linux_headless) is enabled, After click on web element it is showing blank page in selenium automation.
2.And if I disable the Headless mode(chrome driver), everything works fine in selenium automation.
Browser details:
Google Chrome 114.0.5735.133 (Official Build) (64-bit)
We have tried:
1.driver.navigate().refresh();
2.Get userAgent of browser first:
String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
System.setProperty("useragent",userAgent);
//Add it to browser option as below
options.addArguments("--user-agent="+System.getProperty("useragent"));
答案1
得分: 0
使用新版的Chrome无头模式:--headless=new
,而不是旧版的(--headless
)。新版使无头模式与普通Chrome工作方式相同:
options.addArguments("--headless=new");
有关详细信息,请参阅 https://stackoverflow.com/a/73840130/7058266。
英文:
Use the newer Chrome headless mode: --headless=new
, instead of the old one (--headless
). The new one makes headless mode work the same way as regular Chrome:
options.addArguments("--headless=new");
For details, see https://stackoverflow.com/a/73840130/7058266
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论