I have the following code line used in selenium python script:
from selenium import webdriver
driver.find_element_by_xpath(u\"//span[text()=\'\" + cat2 + \"
In XPath 1.0, which is used by browsers and therefore by Selenium, there is no native way of escaping string literals (which was remedied in XPath 2.0). A few workarounds are mentioned by this poster, which includes:
concat('"', "Here's Johnny", '"', ", said Johnny."), which combines to the literal: "Here's Johnny", said Johnny..In your case, this would work:
driver.find_element_by_xpath(u"//span[text()=\"" + cat2 + "\"]").click()
Another way around this is to set an XPath variable to contain the value of your string literal, which helps in readability. But I couldn't find how to do it with the web drivers for Selenium, which typically means there is no such method available.