Reputation: 13
When trying to create a filepath in Python with Selenium to run.
I tried running the code line by lane and for this code:
path = os.path.expanduser("~\Anaconda2\selenium\webdriver\firefox\amd64\geckodriver.exe")
In the variable explorer it shows as below:
C:\Users\username\Anaconda2\selenium\webdriverirefox(bullet character)md64\geckodriver.exe
Thus running into an error [Error 267] The directory name is invalid
.
Can someone help me?
Thanks!
Upvotes: 0
Views: 90
Reputation: 181
You need to escape (\
) your backslashes, or put an r
before your string, which string2
below demonstrates.
>>> string1 = "~\Anaconda2\selenium\webdriver\firefox\amd64\geckodriver.exe"
>>> string1
'~\\Anaconda2\\selenium\\webdriver\x0cirefox\x07md64\\geckodriver.exe'
>>> string2 = r"~\Anaconda2\selenium\webdriver\firefox\amd64\geckodriver.exe"
>>> string2
'~\\Anaconda2\\selenium\\webdriver\\firefox\\amd64\\geckodriver.exe'
Upvotes: 1