【发布时间】:2021-11-25 15:00:51
【问题描述】:
现在一整天都在测试Kameleo.LocalApiClient。注意到一些奇怪的事情。
var client = new KameleoLocalApiClient(new Uri(KameleoBaseUrl));
client.SetRetryPolicy(null);
// Search Chrome Base Profiles
var baseProfileList = await client.SearchBaseProfilesAsync("desktop", "windows", "chrome", "ru-ru");
Random rnd = new Random();
var baseId = rnd.Next(1, baseProfileList.Count);
// Create a new profile with recommended settings
// Choose one of the Firefox BaseProfiles
// You can set your proxy up in the setProxy method
var requestBody = BuilderForCreateProfile
.ForBaseProfile(baseProfileList[baseId].Id)
.SetRecommendedDefaults()
.SetProxy("http", new Server("zproxy.lum-superproxy.io", 22225, "lum-customer-joshua901-zone-zone2", "5inhblkgrzxj"))
//.SetProxy("http", new Server("zproxy.lum-superproxy.io", 22225, "lum-customer-joshua901-zone-russiashared-ip-181.214.180.215", "lqoz0ee2hbvb"))
.SetLauncher("chrome")
//.SetScreen("--window-size", 500, 783)
.Build();
var profile = await client.CreateProfileAsync(requestBody);
// Start the browser
await client.StartProfileAsync(profile.Id);
// Connect to the running browser instance using WebDriver
var uri = new Uri($"{KameleoBaseUrl}/webdriver");
var opts = new ChromeOptions();
opts.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
opts.AddExcludedArgument("enable-automation");
opts.AddArgument("--window-size=500,783");
opts.AddArgument("disable-infobars");
opts.AddArgument("--incongito");
opts.AddArgument("--disable-extensions");
opts.AddArgument("disable-gpu");
opts.AddArgument("headless");
opts.AddArgument("--ignore-certificate-errors");
opts.AddArgument("no-sandbox");
opts.AddArgument("--silent-launch");
opts.AddArgument("--no-startup-window");
//var webdriver = new RemoteWebDriver(uri, opts);
_driver = new RemoteWebDriver(uri, opts)
我想将额外的 ChromeOptions 添加到我的驱动程序中,尤其是能够以“无头”模式运行。
即使我在上面定义了 ChromeOptions 并使用这些选项创建了 RemoteWebDriver,chrome 浏览器仍然会弹出并且不会以无头模式运行。
我如何以及如何添加我的附加选项?
【问题讨论】:
-
你试过
opts.AddArgument("--headless");吗? -
是的,我已经尝试了各种可能性。 1 个破折号
-headless,2 个破折号--headless,没有破折号headless -
您确定可以为远程 Web 驱动程序提供这些参数吗?
标签: selenium selenium-chromedriver browser-automation remotewebdriver kameleo