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.

5
  • your xpath is not valid, because of which you are seeing issue Commented Sep 21, 2017 at 15:30
  • @thebadguy Ok, but how will I correctly compose the query? Commented Sep 21, 2017 at 15:34
  • try "//span[@ng-bind=\"'@' + user.username\"]" just escaping quotes , reference stackoverflow.com/questions/32759318/… Commented Sep 21, 2017 at 15:45
  • use driver.find_element_by_xpath("//span[@ng-bind=\"'@' + user.username\"]").text for getting the text Commented Sep 21, 2017 at 15:49
  • by.xpath('//span[@ng-bind="{0}"]'.format("'@' + user.username")); or by.xpath('//span[@ng-bind="\'@\' + user.username"]'); Commented Sep 21, 2017 at 16:19

1 Answer 1

2

Try with something like this:

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.