最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

硒使用nodejs在一组等于元素中单击特定元素

IT培训 admin 4浏览 0评论

硒使用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]

发布评论

评论列表 (0)

  1. 暂无评论