chromewebdriver not launching

57 views Asked by At

Chrome web driver isn't launching in my code.

This is my code:

from selenium import webdriver
driver=webdriver.Chrome("C:\Users\acer\Downloads\chromedriver-win64")
driver.get("https://google.com")

It gives me this error:

C:\Users\acer\PycharmProjects\python_selenium\.venv\Scripts\python.exe C:\Users\acer\PycharmProjects\python_selenium\Test_case01\Login.py 
  File "C:\Users\acer\PycharmProjects\python_selenium\Test_case01\Login.py", line 2
    driver=webdriver.Chrome("C:\Users\acer\Downloads\chromedriver-win64")
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Process finished with exit code 1

Change to following script:

from selenium import webdriver
driver=webdriver.Chrome("C:\Users\acer\Downloads\chromedriver-win64\chromedriver.exe")
driver.get("https://google.com")
1

There are 1 answers

0
Aleti On

The path is a normal string. Try using driver=webdriver.Chrome(r"C:\Users\acer\Downloads\chromedriver-win64\chromedriver.exe")

In a normal string python will escape with \ but if you use r in front of the string will make it a raw string. The other option will be to escape the \ symbol like this \\