Steven Steven - 2 months ago 11
Python Question

Pybot - how to specify an xpath for an "a href" link

I am trying to run a very simple test with pybot using the xpath but for some reason it keeps saying that my xpath is not a valid, even though I am following the documentation straight from http://robotframework.org/Selenium2Library/Selenium2Library.html

This is all I have in my test:

Temp test
Set Selenium Timeout 60s
Set Selenium Speed 1s
Open Browser http://google.com chrome
Click Link xpath=//a[@href=‘https://mail.google.com/mail/?tab=wm&authuser=0']
Sleep 3s
Close All Browsers


But for whatever reason it keeps complaining

Message: invalid selector: Unable to locate an element with the xpath expression //a[@href=‘/‘] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[@href=‘/‘]' is not a valid XPath expression.

I have seen other people follow the same format with no issues. I have also never had issues with xpath expressions for selenium with java in the past.

Answer

Notice how your opening quote is different from the closing one?

Change the in your syntax to a proper ' -- and check that the close-quote in your real code is also a genuine ASCII-character-39 single-quote, not some fancy Unicode curly created by being copied/pasted through Microsoft applications or such.