我们可以在硒中添加驱动程序作为Maven缺陷吗 [英] Can we add drivers in selenium as maven depandancies

查看:63
本文介绍了我们可以在硒中添加驱动程序作为Maven缺陷吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在POM中添加gecko驱动程序(即驱动程序或chrome驱动程序)作为脱离吗?我尝试搜索,但无法在 https://mvnrepository.com/artifact 上对其进行罚款.为什么不将它们放置在Maven存储库中呢?

Can we add gecko driver , ie driver or chrome driver as depandancy in POM? I tried to search but was not able to fine them on https://mvnrepository.com/artifact. Any reason why they are not placed on the maven repository ?

推荐答案

所提到的评论很少,该驱动程序是可执行二进制文件. Maven只是一个依赖关系存储库,无法为您提供帮助.当前,例如要在firefox上运行selenium,我们需要编写:

As few comments mentioned, that driver are executable binary files. Maven cannot help you with that as it's just a dependency repository. Currently to run selenium for example on firefox we need to write :

System.setProperty("webdriver.gecko.driver", "driverpath/.exe");
WebDriver driver = new FirefoxDriver();

但是,如果有第一行代码,您将不再需要下载dirver二进制文件,而是有了新的解决方案.它称为WebDriverManager,它是可以使用Maven pom文件添加的依赖项. 这将在运行时以最新版本号调用驱动程序. 您现在只需要写:

However we have new solution that will make us get rid if the first line of code and you won't need to download the dirver binary files anymore. Its called WebDriverManager and it's a dependency that can be added using Maven pom file. This will call the driver during run time with the latest version number. All you need to write now is :

WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();

,您需要在pom文件中添加此依赖项

and you need to add this dependency in the pom file

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>2.2.1</version>
</dependency>

有关此的更多信息,请转到Github链接检查驱动程序的所有其余部分,例如chrome,即等等.

For more information about this please go to Github link to check all the rest of the driver like chrome , ie , etc.. WebDriverManagerLink

这篇关于我们可以在硒中添加驱动程序作为Maven缺陷吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆