首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在c#中运行Selenium Brave web浏览器webdriver?

如何在c#中运行Selenium Brave web浏览器webdriver?
EN

Stack Overflow用户
提问于 2020-06-13 19:11:06
回答 1查看 178关注 0票数 0

有好心的人可以帮我。我有一个问题,那就是我不能在Brave和visual studio中运行Selenium。有没有人能帮我写一下代码?执行它会是什么呢?因为在visual studio webdriver自动运行chrome的情况下,我想让它运行Brave。谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-10-10 10:00:28

要求:

  • 安装Nuget包(Selenium.WebdriverSelenium.Chrome.Webdriver)

代码语言:javascript
复制
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似乎很容易使用。您可以查看他们的APIDocumentation,其中包括C#编程语言的用法和示例。

如果您懒得查找cheat sheet或文档,您也可以使用它作为参考。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62358915

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档