【发布时间】:2016-07-09 13:29:02
【问题描述】:
这里是源代码:
<div id="alert_signin" class="alert_modal_error">
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
Invalid username or password.
</div>
</div>
我真正需要的是检查消息“无效的用户名或密码”。出现(python + selenium webdriver)。但是我很不幸地发现它使用 xpath 之类的
find_element_by_xpath('//div[@id=\'alert_signin\']/div[@class=\'alert\']').text
所以我决定使用消息文本找到确切的 xpath。我尝试了几种选择,例如
find_element_by_xpath('//*[text()[contains(.,\'Invalid\')]]')
或
find_element_by_xpath('//*[contains(., \'Invalid username or password.\')]')
但每次都得到"NoSuchElementException: Unable to locate element: {"method":"xpath","selector": blablabla"
请指教
【问题讨论】:
标签: xpath