Selenium Chrome driver – SyntaxError: (unicode error) 'unicodeescape' codec

Question:

I am trying to type my first GUI test in pycharm with selenium.

I installed selenium by cmd
raport:

C:>pip install selenium
Requirement already satisfied: selenium in c:usersadminappdatalocalprogramspythonpython37-32libsite-packages (3.141.0)
Requirement already satisfied: urllib3 in c:usersadminappdatalocalprogramspythonpython37-32libsite-packages (from selenium) (1.24.1)

Then I wrote some code in pycharm:

from selenium import webdriver
import time
driver = webdriver.Chrome("C:UsersAdminDesktop")
driver.get("https://www.youtube.com/watch?v=FFDDN1C1MEQ");

And that is what happened when I clicked start :

File “C:/Users/Admin/PycharmProjects/untitled/venv/test.py”, line 3
driver = webdriver.Chrome(“C:UsersAdminDesktop”)
^
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated UXXXXXXXX escape

win.10
I don’t know what I am doing wrong.
Thanks for any help and have a good day.

edit:
Yes, thanks it works.
I have another error now:

C:UsersAdminPycharmProjectsuntitledvenvScriptspython.exe C:/Users/Admin/PycharmProjects/untitled/venv/test.py
Traceback (most recent call last):
  File "C:/Users/Admin/PycharmProjects/untitled/venv/test.py", line 1, in <module>
    from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

Process finished with exit code 1

Answers:

As you can see in the error the problem is in line 3.

What you need is to specify the path to your chromedriver.exe

Just change it to driver = webdriver.Chrome("C:your path to chromedriverchromedriver.exe")

As for your second issue, it seems you don’t have selenium installed:

Just run pip install selenium in your CMD (you need pip too)

For installing pip see here.

For installing selenium see here.

Hope you find this helpful!

Answered By: Moshe Slavin

Backslashes in Python are escaping characters.
When you are going to use Windows path’s make sure to use a raw string, to prevent Python trying to escape the string:

driver = webdriver.Chrome(r"C:UsersAdminDesktopchromedriver.exe")
Answered By: Maurice Meyer