【发布时间】:2019-11-19 21:17:45
【问题描述】:
我正在尝试通过 xpath 获取输入元素,但返回语句为 false。
当我尝试获取输入的唯一同级标签时,它返回 true。我也尝试通过输入输入[@type="checkbox"] 来获取它,但它也失败了。
try {
var select2 = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.xpath('//div[@class="arcHier arcVert arcTree"]/ol/li/ul/li[3]/div[@class="dragNode"]/label')))
WDS.log.info('select2 found')
var select3 = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.xpath('//div[@class="arcHier arcVert arcTree"]/ol/li/ul/li[3]/div[@class="dragNode"]/input')))
WDS.log.info('select3 found')
}
catch (err) {
WDS.log.error('item not found')
}
HTML 结构:
<li id="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef_LI" style="line-height:19px;border-color:#a0a0a0;color:#000000;" class="LI_1_2">
<label class="arcSelectable" style="height:19px;">
<input type="checkbox" id="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef_X" class="arcHpCbox" checked="checked">
<span class="arcMenuCheckbox"></span>
</label>
<div class="dragNode">
<input type="checkbox" id="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef" style="margin-top:3px;">
<label draggable="false" for="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef" style="height:19px;">
<span class="SPAN_1_2" style=""></span>
0001 Training_Test_Company
</label>
</div>
</li>
日志文件:
- 2019-07-10 10:55:33,187 信息 c.g.j.p.w.s.WebDriverSampler: select2 找到了
- 2019-07-10 10:55:43,310 错误 c.g.j.p.w.s.WebDriverSampler:项目不 找到了
【问题讨论】:
-
请阅读为什么screenshot of HTML or code or error is a bad idea。考虑使用基于格式化文本的相关 HTML、代码试验和错误堆栈跟踪来更新问题。
-
你能在开发工具中检查输入节点有多少条目吗?
-
@cruisepandey 有 116 个输入元素
-
我想我们需要更多的 HTML 代码来找到 xpath。
标签: javascript selenium selenium-webdriver jmeter automated-tests