首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我们如何在selenium webdriver中不同字段名的按钮上点击相同的类名

我们如何在selenium webdriver中不同字段名的按钮上点击相同的类名
EN

Stack Overflow用户
提问于 2016-01-18 17:05:52
回答 3查看 1.4K关注 0票数 0

我们如何在selenium webdriver中为不同字段名的开/关按钮点击相同的类名

(例如) 1)电子邮件通知-一个要素2)系统费用-第二个要素3)生日-第三个要素

这些都有相同的类名-“切换组”.How我们点击这三个按钮。

我们如何编写此不像复选框选项的单击按钮操作

EN

回答 3

Stack Overflow用户

发布于 2016-01-18 17:13:47

您可以根据元素的文本查找元素

代码语言:javascript
复制
driver.findElement(By.linkText("first")).click();

代码语言:javascript
复制
driver.findElement(By.partialLinkText("first")).click();
票数 0
EN

Stack Overflow用户

发布于 2016-01-18 17:16:42

正如您在此helpful article中所看到的,您可以使用许多方法:

代码语言:javascript
复制
driver.findElement(By.id("element id"))

driver.findElement(By.className("element class"))

driver.findElement(By.name("element name"))

driver.findElement(By.tagName("element html tag name"))

driver.findElement(By.cssSelector("css selector"))

driver.findElement(By.link("link text"))

driver.findElement(By.xpath("xpath expression"))
票数 0
EN

Stack Overflow用户

发布于 2016-01-18 17:37:03

代码语言:javascript
复制
import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class check {

    public static void main(String[] args) {

       WebDriver driver = new FirefoxDriver();
       List<WebElement> we = new ArrayList<WebElement>();
       we = driver.findElements(By.name("chk"));
           we.get(0).click(); // clicks on "first"
           we.get(1).click(); // clicks on "second"
           we.get(2).click(); // clicks on "third"

     }
}


/* another option */


import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class check {

    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();
       List<WebElement> we = new ArrayList<WebElement>();
       we = driver.findElements(By.name("chk"));

       for(WebElement check: we)
       {
           check.click(); // click all the 3 elements and comes out of loop

       }

    }

}

希望这能帮上忙..

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34850836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档