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

9

9

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!

Chumley answered 20/7, 2015 at 7:50 Comment(1)
If you want to start selenium webDriver using chrome, first you should set property for the chrome. Otherwise you will get IlegalStateException.Potful
A
5

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!

UPDATE: After Selenium 3 even Firefox needs geckodriver.

Aculeus answered 21/7, 2015 at 13:12 Comment(4)
When i try to do this I get an error that firefox does need a driver. OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variableFung
Oh it looks like in Selenium 3 firefox is no longer included.Fung
For Selenium 3.0 all browsers need a server component. Only option is to get this exe whielisted by your firm and allow it to be downloaded.Fairing
i dont want to put any exe on my server. is there really no alternative for this accepted answer?Hircine
J
6

Yes, you can use without downloading chromedriver.exe file

pip install webdriver-manager

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

go to the official website for more info.

https://pypi.org/project/webdriver-manager/

Jabin answered 28/6, 2021 at 7:43 Comment(3)
How does this work behind a proxy?Tiber
But this still installs Chome, right? Which is annoying: why do I want to install anything at all, I already have Chome/Chromium in my system, I simply need it to get the browser from $PATH.Counts
This answer is misleading and wrong: all webdriver-manager do is it simply downloads chromedriver (or geckodriver for Firefox). So no, as mentioned in the accepted answer using a browser without a driver binary is apparently not possible.Counts
A
5

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!

UPDATE: After Selenium 3 even Firefox needs geckodriver.

Aculeus answered 21/7, 2015 at 13:12 Comment(4)
When i try to do this I get an error that firefox does need a driver. OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variableFung
Oh it looks like in Selenium 3 firefox is no longer included.Fung
For Selenium 3.0 all browsers need a server component. Only option is to get this exe whielisted by your firm and allow it to be downloaded.Fairing
i dont want to put any exe on my server. is there really no alternative for this accepted answer?Hircine
B
5

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.

Beem answered 4/11, 2017 at 18:22 Comment(0)
T
5

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");  
Truthful answered 6/11, 2019 at 6:30 Comment(0)
P
0

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.

Phosphor answered 20/7, 2015 at 7:59 Comment(2)
Hi Ketan, I already have google chrome installed and will be able to run chrome.exe. However, I cannot run chromedriver.exe. Can it still work?Chumley
@learning_dev_me, No, you need to use chromedriver.exe if you want to work on chrome browser.Interpretive
S
0

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

Scoff answered 20/7, 2015 at 9:5 Comment(0)
S
0

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
Serous answered 16/7, 2017 at 1:41 Comment(0)
S
0

'Yes. If your are using Selenium 4.9.0. Then you dont need to explicitly use chromedriver.exe. Jar "Selenium-chrome-driver-4.9.0" will be included in the package.

Spinner answered 26/4, 2023 at 10:22 Comment(0)
S
0

You can use Bonigarcia WebdriverManager. It will take care of everything. https://github.com/bonigarcia/webdrivermanager

It also has maven and gradle dependency in handy. Very easy to use

Seleucia answered 13/12, 2023 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.