複選框交互
複選框交互
在本節中,我們將瞭解如何與交互複選框。我們可以使用「click」方法選擇入住按鈕選項,然後取消選擇使用相同的「click」方法。
讓我們明白,如何使用交互複選框 - http://www.calculator.net/mortgage-calculator.htmll。我們還可以檢查是否選擇/啓用/可見光的複選框。
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class webdriverdemo
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();
//Puts a Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.navigate().to("http://www.calculator.net/mortgage-calculator.htmll");
driver.manage().window().maximize();
// Click on check Box
driver.findElement(By.id("caddoptional")).click();
System.out.println("The Output of the IsSelected " + driver.findElement(By.id("caddoptional")).isSelected());
System.out.println("The Output of the IsEnabled " + driver.findElement(By.id("caddoptional")).isEnabled());
System.out.println("The Output of the IsDisplayed " + driver.findElement(By.id("caddoptional")).isDisplayed());
driver.close();
}
}
輸出
在執行時,該複選框被點擊命令後,選中(因爲它是默認選中)和命令的輸出顯示在控制檯中。
0 條評論,你可以發表評論,我們會進行改進
