Unable to click on a radio button in Selenium Webdriver

后端 未结 8 418
遥遥无期
遥遥无期 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条回答
  •  被撕碎了的回忆
    2021-01-23 21:55

    I tried many different ways to force selenium to wait for the radio button to be visible but it kept timing out. I eventually had to settle for clicking the label for:

    WebDriverWait wait = new WebDriverWait(driver, 20);
    WebElement element = driver.findElement(selector);
    wait.until(ExpectedConditions.elementToBeClickable(element));
    element.click();
    

    Where selected is defined by:

    By selector = By.cssSelector(cssSelector);
    

    With HTML looking like this:

    ...
    
    ...

    And an example string cssSelector of:

    String cssSelector = "label[for='wibble']"
    

提交回复
热议问题