Can I use Selenium (webdriver) for Chrome without using chromedriver.exe?

扶醉桌前 提交于 2020-06-12 05:05:26

问题


I've been trying to study Selenium in ways we can incorporate it in our testing. I've read and watched some tutorial and it basically needs to use chromedriver.exe set as webdriver.chrome.driver property. However, our company policies restrict us from using/executing exe files. As a result, when I try my code for Selenium chrome, I get an error that the exe trying to execute is unauthorize.

So my question is that, is there any way I can use Selenium for chrome without having to use chromedriver.exe? If you know a link for a documentation, turorial or even a youtube guide, please let me know. Thanks!


回答1:


I believe it is not possible to use chrome browser in Selenium without using chromedriver.exe. The same applies to Internet Explorer as well.

However, if you are really prohibted from using .exe files, then executing your test scripts in Firefox will be helpful. All you need to do is to add the below code:

driver = new FirefoxDriver();

No need to refer any .exe files when it comes to Firefox. Hope this helps!




回答2:


If your project is Maven based, you can add below dependency. This has ChromeDriverManager class which takes care of chromedriver binary file and also it maintains latest version of binary file, reducing the manual work of maintaining the driver exe file manually.

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

ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();
driver.get("http://www.google.co.in");

I have recently tried this and still have to evaluate pros and cons. Please mention your points on pros/cons if get more information. Thanks.




回答3:


If it is maven based project and you are using latest version of selenium-chrome-driver and webdrivermanager, you can try to use below dependencies in pom.xml

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.7.1</version>
    </dependency>

Use WebDriverManager,

    WebDriverManager.chromedriver().setup();
    WebDriver driver = new ChromeDriver();
    driver.get("http://google.com");  



回答4:


No you cannot. Either you can give the path of the inbuilt exe path of chrome present installation folder or you have to give the chrome exe path. As selenium supports only firefox as build in functionality.




回答5:


No you can not use selenium for chrome browser without using chromedriver.exe




回答6:


It may not be a good practice but you can do it using AutoIT. Launch the chrome browser and AutoIT code using Runtime class in your project.

AutoIT code:

winwait("title","","10")
If winexist("title") Then
   winactivate("title")
endif


来源:https://stackoverflow.com/questions/31511265/can-i-use-selenium-webdriver-for-chrome-without-using-chromedriver-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!