2

I'm trying to find text on the page. Python code using Selenium:

driver.find_element_by_xpath("//span[@ng-bind=''@' + user.username']")

The text I need "@bassale" is on the page:

enter image description here

When executing the code, I get an error:

selenium.common.exceptions.InvalidSelectorException: Message: {"errorMessage":"Unable to locate an element with the xpath expression //span[@ng-bind=''@' + user.username'] because of the following error:\nError: INVALID_EXPRESSION_ERR: DOM XPath Exception 51

Help me find this text on the page.

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • your xpath is not valid, because of which you are seeing issue – thebadguy Sep 21 '17 at 15:30
  • @thebadguy Ok, but how will I correctly compose the query? – Владимир Sep 21 '17 at 15:34
  • try "//span[@ng-bind=\"'@' + user.username\"]" just escaping quotes , reference https://stackoverflow.com/questions/32759318/how-to-escape-single-quote-in-xpath-1-0-in-selenium-for-python – thebadguy Sep 21 '17 at 15:45
  • use driver.find_element_by_xpath("//span[@ng-bind=\"'@' + user.username\"]").text for getting the text – thebadguy Sep 21 '17 at 15:49
  • by.xpath('//span[@ng-bind="{0}"]'.format("'@' + user.username")); or by.xpath('//span[@ng-bind="\'@\' + user.username"]'); – yong Sep 21 '17 at 16:19

1 Answers1

2

Try with something like this:

driver.find_element_by_xpath("//span[@ng-bind=\"'@' + user.username\"]")

miczza
  • 165
  • 2
  • 9