我们如何在selenium webdriver中为不同字段名的开/关按钮点击相同的类名
(例如) 1)电子邮件通知-一个要素2)系统费用-第二个要素3)生日-第三个要素
这些都有相同的类名-“切换组”.How我们点击这三个按钮。
我们如何编写此不像复选框选项的单击按钮操作
发布于 2016-01-18 17:13:47
您可以根据元素的文本查找元素
driver.findElement(By.linkText("first")).click();或
driver.findElement(By.partialLinkText("first")).click();发布于 2016-01-18 17:16:42
正如您在此helpful article中所看到的,您可以使用许多方法:
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"))发布于 2016-01-18 17:37:03
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
}
}
}希望这能帮上忙..
https://stackoverflow.com/questions/34850836
复制相似问题