简体   繁体   English

如何在 selenium 中不设置本地驱动程序的情况下启动浏览器? (不访问本地chromeDriver.exe)

[英]How to launch browser without setting local driver in selenium? (Without accessing local chromeDriver.exe)

public MainActionFlow() {
    System.setProperty("webdriver.chrome.driver", "C://ChromeDriver_test//chromedriver.exe");
    driverForTesting = new ChromeDriver();
    this.driverForTesting.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

is there any way that we can launch browser without local drivers?有什么方法可以在没有本地驱动程序的情况下启动浏览器?

I think what you want is- downloading all the driver executables automatically?我认为您想要的是-自动下载所有驱动程序可执行文件? If so, yes its possible by using BoniGarcia's Webdrivermanager.如果是这样,是的,可以使用 BoniGarcia 的 Webdrivermanager。 WebDriverManager helps to download binanries/executables in an automated way. WebDriverManager 有助于以自动方式下载二进制文件/可执行文件。 It supports browsers such as Chrome, Firefox, Opera, PhantomJS, Microsoft Edge, or Internet Explorer.它支持 Chrome、Firefox、Opera、PhantomJS、Microsoft Edge 或 Internet Explorer 等浏览器。

We just need to add its dependency through Maven or Gradle to download all the necessary drivers.我们只需通过 Maven 或 Gradle 添加其依赖项即可下载所有必要的驱动程序。 It will download ONLY if they are not present on the WebDriverManager cache (~/.m2/repository/webDriver by default).仅当 WebDriverManager 缓存中不存在它们时才会下载(默认为 ~/.m2/repository/webDriver)。

Add following dependency in your POM在您的 POM 中添加以下依赖项

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>4.4.3</version>
    <scope>test</scope>
</dependency>

Once this is done you can instantiate your driver session by just below line -完成此操作后,您可以通过以下行实例化您的驱动程序 session -

WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();

visit this page for more details- https://github.com/bonigarcia/webdrivermanager访问此页面了解更多详情 - https://github.com/bonigarcia/webdrivermanager

You should have some webdriver running at remote computer.您应该在远程计算机上运行一些 webdriver。 Then You do somehting like this:然后你做这样的事情:

ChromeOptions chromeOptions = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://www.example.com"), chromeOptions);
driver.get("http://www.google.com");
driver.quit();

Where http://www.example.com is the URL your remote web driver is accessible with.其中http://www.example.com是 URL 您的远程 Z2567A5EC9705EB7AC2DZ98403 驱动程序可访问。

See the details here .请参阅此处的详细信息。

Used below code, it downloads driver in runtime and accesses the drivers在下面的代码中使用,它在运行时下载驱动程序并访问驱动程序在此处输入图像描述 Pom.xml Pom.xml 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有 ChromeDriver.exe 的情况下从 Selenium 远程 Web 驱动程序启动 GoogleChrome - How to Launch GoogleChrome from Selenium Remote Web Driver without ChromeDriver.exe 硒chromedriver.exe - Selenium chromedriver.exe chromedriver.exe和selenium-chrome-driver.jar之间的区别 - difference between chromedriver.exe and selenium-chrome-driver.jar 硒找不到chromedriver.exe - selenium is not locating chromedriver.exe 码头工人 驱动程序可执行文件不存在:/chromedriver.exe - Docker. The driver executable does not exist: /chromedriver.exe Java Selenium Chromedriver.exe 不存在 IllegalStateException - Java Selenium Chromedriver.exe Does not Exist IllegalStateException Selenium Java:当程序退出时保证chromedriver.exe关闭 - Selenium Java: Guarantee chromedriver.exe shutdown when program exits Selenium WebDriver 3.0.1 chromedriver.exe 2.25 --whitelisted-ips=&quot;&quot; - Selenium WebDriver 3.0.1 chromedriver.exe 2.25 --whitelisted-ips=“” 如何在不将IE驱动程序或Chrome驱动程序添加到硒Web驱动程序的情况下启动已安装的浏览器? - How can I start installed browser without adding IE driver or Chrome driver in selenium web driver? 无法在 Selenium 网格中运行测试 Maven 设置中引用 Chromedriver.exe - Unable to run tests in Selenium Grid referencing Chromedriver.exe in Maven setup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM