0

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!

0

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

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.