package testWd;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class findEle {
@Test
public void findElement() throws InterruptedException {
System.setProperty(“webdriver.chrome.driver”, “D:/01 Learn WebDriver/chromedriver.exe”);
WebDriver dr = new ChromeDriver();
dr.manage().window().maximize();
dr.get(“http://www.divcss5.com/yanshi/checkbox.html”);
//定位一组元素,全部选中
/*List<WebElement> els = dr.findElements(By.name(“Fruit”));
System.out.println(els.size());
for(WebElement el:els) {
el.click();
//Thread.sleep(3000);
}*/
//定位一组元素
List<WebElement> els = dr.findElements(By.name(“Fruit”));
//els.get(0).click(); //选取第一个
//els.get(els.size()-1).click(); //选取最后一个
//也可以定位单个元素,然后选中
WebElement el = dr.findElement(By.xpath(“/html/body/form/label[2]/input”));
el.click();
//Thread.sleep(3000);
//dr.quit();
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/195354.html