Marie10
Marie10

Reputation: 161

Can't open web browser using selenium chromedriver on windows 10

I'm trying to open a web browser using Selenium Chromedriver on Windows 10 with python in jupyter notebooks through an ubuntu command prompt. I've read stack overflow posts and tried to solve based on their answers, but I'm stuck in a loop where I keep receiving the same 3 errors.

Here is what I have installed:

OS - Windows 10, 1709, 64-bit Selenium - 3.8.1 Chromedriver - 2.45 Chrome - Version 71.0.3578.98 Python - 3.5.2

I tried various websites. The goal is to eventually get to a social media login page, but i'm stuck at opening a new blank web browser.

Here is my starting code:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.imdb.com/")

WebDriverException: Message: 'chromedriver' executable may have wrong permissions.

Then I tried the following:

from selenium import webdriver
chromedriver = "C:/Users/xxxx/AppData/Local/lxss/home/xxxx/chromedriver.exe"
browser = webdriver.Chrome(chromedriver)
browser.get('https://www.imdb.com/')

WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH.

Here are the steps I have taken:

  1. I added a PATH under environment variables to the folder - (C:\Users\xxxxx\AppData\Local\lxss\home\xxxx),
  2. I tried using \, and /, and even \
  3. Once I added the PATH, I tried the following two codes (and various versions) and received the same error:

A.

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\xxxx\AppData\Local\lxss\home\xxxx)
driver.get("https://www.imdb.com/")

B.

from selenium import webdriver
chromedriver = r'C:\Users\xxxx\AppData\Local\lxss\home\xxxx\chromedriver.exe'
driver = webdriver.Chrome(chromedriver)
driver.get("https://www.imdb.com/")

WebDriverException: Message: 'C:\Users\xxxx\AppData\Local\lxss\home\xxxx' executable may have wrong permissions.

Then I did the following: - Went to file Properties, under General, took off Read-only (Windows permissions) - Went to file Properties, under Security and changed permissions to Full Control - In the C:\Users\xxxxx\AppData\Local\lxss\home\xxxx file, I changed the permissions using chmod 777 -R in my command prompt. Then I tried the following code:

from selenium import webdriver
import os
chromedriver = r'C:\Users\xxxx\AppData\Local\lxss\home\xxxx\chromedriver.exe'
driver = webdriver.Chrome(os.path.join(os.getcwd(), 'chromedriver.exe'))
driver.get("https://www.imdb.com/")

WebDriverException: Message: Service /home/ariggs/chromedriver.exe unexpectedly exited. Status code was: 1

I am stuck between these three error messages. Does anyone have another suggestion for a beginner?

Upvotes: 4

Views: 5969

Answers (2)

Sayad Ahmed Shaurov
Sayad Ahmed Shaurov

Reputation: 537

You can do this way.

Step 1: Download chrome driver from this link (download the specific version as chrome): http://chromedriver.chromium.org/downloads

Important: check your chrome version first. Go to help -> about Google Chrome, to see the version of your chrome.

Step 2: After downloading extract and save the chromedriver file in a specific folder like, C:\selenium go to environment variable and add a new path, C:\selenium

Step 3 Double click on the chromedriver application and then restart your command prompt. (If you are using conda environment.)

Upvotes: 0

Jens Dibbern
Jens Dibbern

Reputation: 1454

You can actually start Windows executables from a linux subsystem as it is described here https://learn.microsoft.com/en-us/windows/wsl/interop.

But you have to keep in mind that Selenium and ChromeDriver communicate over a network connection. Actually chromedriver starts its own http server and Selenium sends requests and receives responses over http. (see https://sqa.stackexchange.com/questions/28358/how-does-chromedriver-exe-work-on-a-core-and-fundamental-level)

According to Microsoft, WSL and Windows share the same IP address and network connections via localhost are supported. But in your case there seems to be a problem during the startup.

You can start a remote webdriver on windows with Python and connect to that.

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import subprocess

subprocess.run(["d:\\develop\\remotewebdriver.cmd", ""])

driver = webdriver.Remote(
   command_executor='http://localhost:4444/wd/hub',
   desired_capabilities=DesiredCapabilities.CHROME)
driver.get('http://www.google.in/')

driver.close()

You need a windows script remotewebdriver.cmd for the remote webdriver that is called from Python:

SET JAVA_HOME=D:\develop\Java\jdk-11.0.2
d:
cd \develop
start D:\develop\Java\jdk-11.0.2\bin\java -Dwebdriver.chrome.driver=d:\develop\chromedriver.exe -jar selenium-server-standalone-3.141.59.jar

You have to adapt the path to your own environment. This setup works for me.

Upvotes: 1

Related Questions