1

I'm having some issues with selenium in my python script.

import time
from selenium import webdriver
browser = webdriver.Chrome(path/to/chromedriver)

After executing the script the terminal is just outputting :

SyntaxError: invalid syntax

the problem is in third line

browser = webdriver.Chrome(path/to/chromedriver)

and I don't really know what to do. I'm pretty sure that the chrome driver path is correct tho.

2
  • Are you on windows? Commented Apr 5, 2020 at 1:02
  • Are you literally typing path/to/chromedriver, without quotes? Commented Apr 5, 2020 at 2:40

3 Answers 3

1

I would suggest using the webdriver_manager, as it will take care of downloading the latest stable driver based on the browser version and also takes care of the execution paths.

Use the below 3 simple lines to start the chrome driver.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager``

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

Make sure you have selenium and webdriver_manager libraries added to the project.

Sign up to request clarification or add additional context in comments.

1 Comment

If you feel the issue is resolved, please accept if this/any answer is/was helpful to you. Also Upvote for the benefit of the future readers
1

Should be, assuming you are on windows

browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")

Or

browser = webdriver.Chrome(executable_path="C:\\path\\to\\chromedriver.exe")

Webdriver download

https://sites.google.com/a/chromium.org/chromedriver/downloads

You can also download and install the chromedriver binary

Just import chromedriver_binary. This will add the executable to your PATH so it will be found.

You can also get the absolute filename of the binary with chromedriver_binary.chromedriver_filename.

from selenium import webdriver
import chromedriver_binary  # Adds chromedriver binary to path

driver = webdriver.Chrome()

Comments

0

For Windows:

You have to put the path as a string in quotes "<path to chromdriver>" and would have to use r (for raw) before the string if it only includes single \ e.g. r"C:\Users\user\..." else you don't need it if you path is like "C:\\Users\\user...".

Do:

import time
from selenium import webdriver
browser = webdriver.Chrome(r"<path to chromedriver>")

where "path to chromedriver" is the path to the chromedriver e.g. "C:\Users\<user>\Downloads\chromedriver_win32\chromedriver.exe".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.