Reputation:
In my site, a field has the following XPath (strange for me at the first sight but well):
/html/body/aside/div/ul/li[2]/a/span
So I am using this way:
driver.findElement(By.xpath("/html/body/aside/div/ul/li[2]/a/span]")).click();
But it's not working and the error message is:
The string
'/html/body/aside/div/ul/li[2]/a/span]'
is not a valid XPath expression.
Could you help me, please? Thank you :)
Upvotes: 0
Views: 109
Reputation: 2972
You had a ]
in the end of your string. Remove this and it will work.
On a side not it is not necessary to write the /html/body/
. You could shorter the XPath by using
driver.findElement(By.xpath(".//aside//div//ul//li[2]//a//span")).click();
Upvotes: 0
Reputation: 1939
Here you go:
driver.findElement(By.xpath("/html/body/aside/div/ul/li[2]/a/span")).click();
Upvotes: 1