如何使用 Selenium java webdriver 選擇複選框?
我們可以使用 Selenium 來選擇複選框。在 html 文件中,每個複選框都有一個屬性 type,其值設定為複選框。為了選擇一個複選框,我們首先要用任何定位器識別出一個複選框,然後對其應用 click() 方法。

示例
程式碼實現方式。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class CheckBoxSelect{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url ="https://tutorialspoint.tw/selenium/selenium_automation_practice.htm";
driver.get(url);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// identify element
WebElement l=driver.findElement(By.xpath("//*[@value='Manual Tester']"));
// select checkbox with click()
l.click();
driver.quit();
}
}輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP