Need Python Help

Hello guys I need help with my Python (Python3) code because I get this error every time when I run the program:

Traceback (most recent call last): File “/Users/myname/PycharmProjects/untitled/IGBot.py”, line 60, in <module> photographyIG.login() File “/Users/myname/PycharmProjects/untitled/IGBot.py”, line 19, in login login_button = driver.find_element_by_xpath("//a[@href’/accounts/login’]") File “/Users/myname/PycharmProjects/untitled/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File “/Users/myname/PycharmProjects/untitled/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 978, in find_element ‘value’: value})[‘value’] File “/Users/myname/PycharmProjects/untitled/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 321, in execute self.error_handler.check_response(response) File “/Users/myname/PycharmProjects/untitled/venv/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py”, line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: Given xpath expression “//a[@href’/accounts/login’]” is invalid: SyntaxError: The expression is not a legal expression.

It appears you are trying to locate a specific element in a web page. The problem is your xpath syntax is incorrect.

As you’ve not provided the source code or any other data to show how that Xpath was determined, it is difficult to help further. You might review the locating elements page.

The answer to this Stack Overflow question may also help.

1 Like