Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Se (6)-locate a set of elements

Shulou Source: shulou.com Published: 2022-06-03 03:59:31 10月04日 Update

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", "DJV 01 Learn WebDriver/chromedriver.exe")

WebDriver dr = new ChromeDriver ()

Dr.manage (). Window (). Maximize ()

Dr.get ("http://www.divcss5.com/yanshi/checkbox.html");"

/ / locate a set of elements and select all of them

/ * List els = dr.findElements (By.name ("Fruit"))

System.out.println (els.size ())

For (WebElement el:els) {

El.click ()

/ / Thread.sleep (3000)

} * /

/ / locate a set of elements

List els = dr.findElements (By.name ("Fruit"))

/ / els.get (0) .click (); / / Select the first one

/ / els.get (els.size ()-1). Click (); / / Select the last one

/ / you can also locate a single element and select

WebElement el = dr.findElement (By.xpath ("/ html/body/form/label [2] / input"))

El.click ()

/ / Thread.sleep (3000)

/ / dr.quit ()

}

}

Tags: Element positioning single Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Shulou Tech Info vpn Linux