Unable to click on a radio button in Selenium Webdriver

后端 未结 8 432
遥遥无期
遥遥无期 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:39

    1. Try to never use Thread.sleep(time)
    2. Never use general Exception catching.

    Instead of it try this, what is more safe:

    public Boolean isDisplayed() {
        try {
            wait.withTimeout(20).until(new ExpectedCondition() {
                @Nullable @Override public Boolean apply(WebDriver input) {
                  return videoComponent.isDisplayed();
                }
            });
        } catch (TimeoutException e) {
            return false;
        }
        return true;
    }
    

    This code will check markup within 20 seconds until it return true.
    If not, after 20 sec it will return false.

    Always specify Exception type, which you want to catch. In other cases it is useless.

提交回复
热议问题