当我选择dropdown1时,我想从下拉列表中选择彼此相互依赖的值 - 它给出了一些特定值,当我选择drop down2时,它会给出一些不同的值,所以使用if条件来检查if(dropdown1 == X) {select y} 其他 {select A}
public class SelectingRadioButtons {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver",
"C:\\geckodriver-v0.17.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://careerendeavour.com/admission-form/registration-form.php");
Select dropdown = new Select(driver.findElement(By.xpath(".//*[@id='center']")));
dropdown.selectByIndex(2);
Select subcourse = new Select(driver.findElement(By.xpath(".//*[@id='course']")));
subcourse.selectByValue("Regular Course");
if (subcourse.equals("Regular Course")) {
Select dropdown1 = new Select(driver.findElement(
By.xpath(".//*[@id='coursetp']")));
dropdown1.selectByValue("GATE");
}
}
}
答案 0 :(得分:0)
您可以按如下方式获取下拉列表的值,
String selectedcourse = subcourse.getFirstSelectedOption().getText();
然后你比较喜欢,
if (selectedcourse.equals("Regular Course")) {
Select dropdown1 = new Select(driver.findElement(By.xpath(".//*[@id='coursetp']")));
dropdown1.selectByValue("GATE");
}