Unable to click on a radio button in Selenium Webdriver

后端 未结 8 488
遥遥无期
遥遥无期 2021-01-23 21:11

I am learning Selenium Webdriver using Java. As a learning example, I tried to open MakeMyTrip, access International Flights page and click on One Way radio but

8条回答
  •  Happy的楠姐
    2021-01-23 21:45

    This is the more proper way to do this and I just tested it and it works fine. The best practice is to wait for the element to be clickable. You do that using WebDriverWait with ExpectedConditions. What this will do is wait up to 20s for the element to appear, when it does execution continues. This is a big advantage over Thread.sleep().

    driver.get("http://www.makemytrip.com/international-flights");
    driver.manage().window().maximize();
    WebDriverWait wait = new WebDriverWait(driver, 20);
    WebElement oneWayRadioButton = wait.until(ExpectedConditions.elementToBeClickable(By.id("one_way_button1")));
    oneWayRadioButton.click();
    System.out.println("Clicked One Way");
    

提交回复
热议问题