有好心的人可以帮我。我有一个问题,那就是我不能在Brave和visual studio中运行Selenium。有没有人能帮我写一下代码?执行它会是什么呢?因为在visual studio webdriver自动运行chrome的情况下,我想让它运行Brave。谢谢
发布于 2020-10-10 10:00:28
要求:
private string chromeDriverPath = @"C:\Path\To\chromedriver.exe"; //Path to chromedriver.exe
private string braveBrowserPath = @"C:\Path\To\brave.exe"; //Path to brave.exe
private ChromeOptions chromeOptions; //Default value of chromeOptions is null
private IWebDriver driver; //Default value of driver is null
public void LoadChrome() {
try
{
Environment.SetEnvironmentVariable("webdriver.chrome.driver", chromeDriverPath); //Sets process evnironment
chromeOptions = new ChromeOptions(); //Initialize chromeOptions
chromeOptions.BinaryLocation = braveBrowserPath; //Sets the location of Brave
driver = new ChromeDriver(chromeOptions); //Initialize driver with chromeOptions
driver.Manage().Window.Maximize(); //Set Brave window maximized
driver.Navigate().GoToUrl("https://www.google.com/"); //Loads page Google
} catch (Exception ex) {
Console.WriteLine(ex.Message); //Print any errors to console log
}
}Selenium似乎很容易使用。您可以查看他们的API和Documentation,其中包括C#编程语言的用法和示例。
如果您懒得查找cheat sheet或文档,您也可以使用它作为参考。
https://stackoverflow.com/questions/62358915
复制相似问题