无法通过xpath找到输入元素

时间:2019-07-10 09:18:41

标签: javascript selenium selenium-webdriver jmeter automated-tests

我正在尝试通过xpath获取输入元素,但是return语句为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>

日志文件:

  1. 2019-07-10 10:55:33,187 INFO c.g.j.p.w.s.WebDriverSampler:select2 找到
  2. 2019-07-10 10:55:43,310错误c.g.j.p.w.s.WebDriverSampler:项目不 找到

1 个答案:

答案 0 :(得分:1)

输入元素可能是一个隐藏的复选框。您可以尝试使用presenceOfElementLocated代替下面的visibilityOfElementLocated

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.presenceOfElementLocated(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')
}
相关问题