Firefox 浏览器在无头模式下运行测试的更新参数是什么?

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

What is the updated argument for Firefox browser to run test (Selenium Java) in headless mode?

问题

我已经尝试将参数设置为 options.addArguments("--headless");,但它不起作用。请注意,我不想使用 setHeadless(Boolean) 方法,因为它现在已被弃用。

我已经通过以下代码在无头模式下使用 Chrome 成功:

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");

driver = WebDriverManager.chromedriver().capabilities(options).create();

我想在 Firefox 中做同样的事情。当我使用 options.addArguments("--headless"); 时,它无法与页面元素交互。我确保没有其他元素遮挡了可交互的元素。

英文:

I have tried to set the argument as options.addArguments("--headless"); but it's not working. Please note that I don't want to use setHeadless(Boolean) method since it's deprecated now.

I have a working Chrome in headless with the following code:

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");

driver = WebDriverManager.chromedriver().capabilities(options).create();

And I want to do the same with Firefox. When I use options.addArguments("--headless"); it can not interact with the page element. I'm assuring that there are no other element to obscure the interactable element.

答案1

得分: 0

在Firefox选项文档中提到,可以使用"-headless"或"--headless"

addArguments("-headless")

完成

FirefoxOptions options = new FirefoxOptions();
options.addArguments("-headless");
WebDriver driver = new FirefoxDriver(options);
英文:

Its mentioned in Firefox options docs use "-headless" or "--headless" also works

addArguments("-headless")

complete

	FirefoxOptions options = new FirefoxOptions();
	options.addArguments("-headless");
	WebDriver driver = new FirefoxDriver(options);

huangapple
  • 本文由 发表于 2023年5月29日 10:10:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76354308.html
匿名

发表评论

匿名网友

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

确定