java - selenium 找不到 Angularjs 元素 - Java
问题描述
我需要从页面中的特定元素中获取文本,这些元素只有唯一的标签“ng-bind="$Gadget.customerSegmentation",并且元素位置可能会根据场景进行更改
我尝试在下面查找元素,但有时它有时不起作用。
@FindBy(xpath = "//div[@ng-bind='$Gadget.customerSegmentation']")
WebElement Customer;
<div class="form_group inline_block" style="width:30%;">
<div class="form_label ng-binding" style="width:30%;">Cust Segmentation:</div>
<div class="form_control ng-binding" title="Low" ng-bind="$Gadget.customerSegmentation" style="width:65%;float:right;">Low</div>
</div>
即使位置改变了也能找到元素。
解决方案
要识别元素,您可以使用以下任一Locator Strategies:
选择器:
@FindBy(css = "div.form_control.ng-binding[title='Low'][ng-bind$='customerSegmentation']") WebElement Customer;
路径:
@FindBy(xpath = "//div[@class='form_control ng-binding' and @title='Low'][contains(@ng-bind, 'customerSegmentation')]") WebElement Customer;
推荐阅读
- javascript - 如何使用javascript获取屏幕高度直到屏幕上的特定元素?
- python - SQLAlchemy:sqlalchemy.exc.CompileError 无法为 NullType() 生成 DDL
- windows - Windows 上的 USB 实例 ID 对设备来说是唯一的吗?
- spring-boot - Springboot 初始化依赖于 Liberty application.xml 并显示类路径未知异常
- android - 如何重命名安卓应用程序?
- javascript - 为什么我会收到 405 错误?
- javascript - Javascript - 无法将数组推送到二维数组
- java - Solr 一次数百万个搜索查询
- node.js - 在 express 中使用路由器
- r - R Shiny:使用输出中的变量在函数之外进行进一步计算