Selenium WebDriver 无界面模式显示空白页面 Selenium Web 元素

huangapple go评论84阅读模式
英文:

Selenium Webdriver Headless Mode shows blank page selenium web element

问题

观察:

  1. 当启用(chrome_linux_headless)时,在单击网页元素后,在Selenium自动化中显示空白页面。
  2. 如果我禁用Headless模式(Chrome驱动程序),则在Selenium自动化中一切正常。

浏览器详细信息:
Google Chrome 114.0.5735.133(官方版本)(64位)

我们已尝试:

  1. driver.navigate().refresh();

  2. 首先获取浏览器的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

huangapple
  • 本文由 发表于 2023年7月6日 18:44:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定