Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Se (6)-locate a set of elements

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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 ()

}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report