0

I am using selenium web driver for an assignment in Python. I am getting a syntax error. I am using google colab and Python 3.

Here is my code

import time
from selenium import webdriver
driver = webdriver.Chrome (r "C:\Users\Anisha\Downloads\chromedriver.exe")
time.sleep(20)

I am getting error

File "<ipython-input-28-7654fa692ce2>", line 1
driver = webdriver.Chrome (r "C:\Users\Anisha\Downloads\chromedriver.exe")
                                                                        ^
SyntaxError: invalid syntax

Please help I am not getting where I am wrong.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jay
  • 41
  • 1
  • 8

2 Answers2

1

If you intend to pass the location of the chromedriver binary in Windows OS you have to:

  • While mentioning the absolute location of the chromedriver binary through the Key / Value pair of executable_path you have to add the binary extension as as well i.e. .exe.
  • While mentioning the absolute location of the chromedriver binary you have to either use the single front slash i.e. \ along with the raw r switch or you have to escape the back slash \\.
  • Your effective line of code will be :

    • Either in this format:

      driver = webdriver.Chrome(executable_path="C:\\Users\\Anisha\\Downloads\\chromedriver.exe")
      
    • Or in this format:

      driver = webdriver.Chrome(executable_path=r'C:\Users\Anisha\Downloads\chromedriver.exe')
      
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Do not leave spaces between raw string literals marker and the string:

r "String" --> r"String"

Use

r"C:\Users\Anisha\Downloads\chromedriver.exe"
Andersson
  • 51,635
  • 17
  • 77
  • 129