如何设置 Selenium 和 ChromeDriver 以在无头模式下运行 [英] How to set up Selenium and ChromeDriver to run in headless mode
本文介绍了如何设置 Selenium 和 ChromeDriver 以在无头模式下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 xUnit、Selenium 和 Chrome Canary(无头模式)运行浏览器测试,但我不断收到此错误:
I am trying to run a browser test using xUnit, Selenium, and Chrome Canary (headless mode) but I keep getting this error:
OpenQA.Selenium.WebDriverException
The HTTP request to the remote WebDriver server for URL
http://localhost:58692/session timed out after 60 seconds.
这是我的代码:
var chromeOptions = new ChromeOptions
{
BinaryLocation = @"C:\Users\<USERNAME>\AppData\Local\Google\Chrome SxS\Application\chrome.exe",
DebuggerAddress = "127.0.0.1:9222"
};
chromeOptions.AddArguments("no-sandbox", "headless", "disable-gpu");
_driver = new ChromeDriver(chromeOptions) {Url = Url};
我对 C# 很陌生,所以我不确定我是否做错了什么,或者我只是缺少一个设置.谷歌搜索上述错误告诉我,我需要设置调试器地址并使用 no-sandbox
标志,但似乎都没有帮助.
I'm quite new to C# so I'm not sure if I'm doing something blatantly wrong, or if I'm just missing a setting. Googling the above error told me that I need to set the debugger address and use the no-sandbox
flag, but neither seem to be helping.
使用这些版本:
selenium 3.4
chromedriver 2.29
xunit 2.2
推荐答案
取出调试器地址就可以了.
Taking out the debugger address made it work.
var chromeOptions = new ChromeOptions
{
BinaryLocation = @"C:\Users\<USERNAME>\AppData\Local\Google\Chrome SxS\Application\chrome.exe",
};
这篇关于如何设置 Selenium 和 ChromeDriver 以在无头模式下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文