硒使用nodejs在一组等于元素中单击特定元素
我正在尝试单击一个具有与其他元素相同属性的元素。在查找并检查是否启用后如何选择要单击的元素?
<html>
<body>
Input 1 <input type="tel" class="myInput">
<br><br>
Input 2 <input type="tel" class="myInput">
<br><br>
Input 3 <input type="tel" class="myInput">
<br><br>
Input 4 <input type="tel" class="myInput">
</body>
</html>
require('chromedriver');
require('log-timestamp');
const webdriver = require('selenium-webdriver');
const chrome = require("selenium-webdriver/chrome");
var until = webdriver.until;
var By = webdriver.By;
async function myMain(){
let driver = new webdriver.Builder().forBrowser('chrome').build();
await driver.get('file:///C:/Users/myUser/Desktop/mypage.html');
await driver.wait(until.elementLocated(By.className("myInput")),15000);
le t btn = driver.findElement(By.className("myInput"));
await driver.wait(until.elementIsEnabled(btn ,15000));
await driver.findElement(By.className("myInput")).click();
};
myMain();
回答如下:如果要选择第四个输入,则可以将xpath与索引4一起使用
//input[@class='myInput'][4]
硒使用nodejs在一组等于元素中单击特定元素
我正在尝试单击一个具有与其他元素相同属性的元素。在查找并检查是否启用后如何选择要单击的元素?
<html>
<body>
Input 1 <input type="tel" class="myInput">
<br><br>
Input 2 <input type="tel" class="myInput">
<br><br>
Input 3 <input type="tel" class="myInput">
<br><br>
Input 4 <input type="tel" class="myInput">
</body>
</html>
require('chromedriver');
require('log-timestamp');
const webdriver = require('selenium-webdriver');
const chrome = require("selenium-webdriver/chrome");
var until = webdriver.until;
var By = webdriver.By;
async function myMain(){
let driver = new webdriver.Builder().forBrowser('chrome').build();
await driver.get('file:///C:/Users/myUser/Desktop/mypage.html');
await driver.wait(until.elementLocated(By.className("myInput")),15000);
le t btn = driver.findElement(By.className("myInput"));
await driver.wait(until.elementIsEnabled(btn ,15000));
await driver.findElement(By.className("myInput")).click();
};
myMain();
回答如下:如果要选择第四个输入,则可以将xpath与索引4一起使用
//input[@class='myInput'][4]