java - 如何通过selenium和java根据html单击“注销”链接
问题描述
这是代码,
<div id="user-tools">
Welcome
<strong>Admin</strong>
/
<a href="/">View</a>
/
<a href="/admin/password_change>Change password</a>
/
</a href="/admin/logout/">Log out</a>
</div>
我正在尝试使用这种方式单击“注销”链接,但没有运气。
driver.findElement(By.xpath("//a[@href='/admin/logout/'])".click();
有任何想法吗 ?谢谢。
解决方案
要单击带有文本作为注销的元素,您可以使用以下任一定位器策略:
选择器:
"div#user-tools a[href='/admin/logout/']"
XPath:
"//div[@id='user-tools']//a[@href='/admin/logout/'][contains(.,'Log out')]"
推荐阅读
- cryptography - (SSL Pining) 设备上的公钥 CA 如何检查服务器的证书
- ajax - 将 JSON 从客户端发送到烧瓶
- c - 将 Switch 语句转换为 if/then 和 if/else 语句
- php - 使用 PHP 的 Nginx 重写规则无法正常工作
- c# - 我应该在 EnityFramework Core 中使用什么 DbContext?
- c - 在循环中编写声明
- javascript - 使用 JavaScript 在模态框上实现表单
- php - 作为数组索引的常量数组值在 foreach 中不起作用
- angular - Angular 6:动态表单
- r - 如何证明 R 中图例的多个部分是合理的?