在本節(jié)中,我們將了解如何使用單選按鈕交互。我們可以使用“click”方法,并取消選擇使用相同的“click”方法選擇一個單選按鈕的選項。
讓我們明白,如何使用單選按鈕交互- http://www.calculator.net/mortgage-payoff-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-payoff-calculator.htmll");
driver.manage().window().maximize();
// Click on Radio Button
driver.findElement(By.id("cpayoff1")).click();
System.out.println("The Output of the IsSelected " + driver.findElement(By.id("cpayoff1")).isSelected());
System.out.println("The Output of the IsEnabled " + driver.findElement(By.id("cpayoff1")).isEnabled());
System.out.println("The Output of the IsDisplayed " + driver.findElement(By.id("cpayoff1")).isDisplayed());
driver.close();
//Close the Browser.
driver.close();
}
}
在執(zhí)行時,被選中的單選按鈕和命令的輸出顯示在控制臺中。