Selenium“在另一个元素中获取元素”

时间:2019-10-04 22:51:45

标签: node.js selenium selenium-webdriver selenium-chromedriver

我试图单击第三个输入框,但我不能使用xpath [3],因为它是由div隔离的。如何获取第三个“ div类价格过滤器”,然后获取输入?

<div class="search-prices">
    <div class="search-price-header">
        <h1>Bid Price:</h1>
        <button class="flat camel-case disabled" disabled="">Clear</button>
    </div>
    <div class="price-filter">
        <div class="info"><span class="label">Min:</span></div>
        <div class="ut-numeric-input-spinner-control">
            <button class="btn-standard decrement-value disabled" disabled=""></button>
                <input type="tel" class="numericInput" placeholder="Any">
                <button class="btn-standard increment-value"></button></div>
    </div>
    <div class="price-filter">
        <div class="info"><span class="label">Max:</span></div>
        <div class="ut-numeric-input-spinner-control">
            <button class="btn-standard decrement-value disabled" disabled=""></button>
                <input type="tel" class="numericInput" placeholder="Any">
            <button class="btn-standard increment-value"></button></div>
    </div>
    <div class="search-price-header">
        <h1>Buy Now Price:</h1><button class="flat camel-case disabled" disabled="">Clear</button>
    </div>
    <div class="price-filter"></div>
        <div class="info"><span class="label">Min:</span></div>
        <div class="ut-numeric-input-spinner-control">
            <button class="btn-standard decrement-value disabled"disabled=""></button>
                <input type="tel" class="numericInput" placeholder="Any">
            <button class="btn-standard increment-value"></button></div>
    </div>
    <div class="price-filter">
        <div class="info"><span class="label">Max:</span></div>
        <div class="ut-numeric-input-spinner-control">
            <button class="btn-standard decrement-value disabled"disabled=""></button>
                <input type="tel" class="numericInput" placeholder="Any">
            <button class="btn-standard increment-value"></button>
        </div>
    </div>
</div>

我尝试过类似的

  var priceFilter = driver.findElement(By.xpath("//div[@class='price-filter'][3]"));   
  var numericInput = priceFilter.findElement(By.xpath("//input[@class='numericInput']"))
  numericInput.click();

但是我的点击总是在第一个输入中发生,知道为什么吗?

3 个答案:

答案 0 :(得分:0)

尝试以下xpath:(//div[@class='price-filter']//input)[3]

答案 1 :(得分:0)

尝试一下,让我知道它是否有效。

var numericInput =priceFilter.findElement(By.xpath("(//input[@class='numericInput'])[3]"))

numericInput.click();

答案 2 :(得分:0)

对我有用的xpath是:

´´´ // div [@ class ='price-filter'] [3] // input [@ class ='numericInput'] ´´

谢谢你们!