Python Selenium,在span中查找文本

时间:2017-09-21 15:24:16

标签: python-3.x selenium

我正在尝试在页面上找到文字。使用Selenium的Python代码:

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

我需要的文字“@bassale”在页面上:

enter image description here

执行代码时,出现错误:

  

selenium.common.exceptions.InvalidSelectorException:消息:{“errorMessage”:“无法找到具有xpath表达式的元素// span [@ ng-bind =''@'+ user.username']因为以下错误:\ n错误:INVALID_EXPRESSION_ERR:DOM XPath异常51

帮我在页面上找到这个文字。

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

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