WebDriver: How to check if an page object web element exists?

后端 未结 8 1707
鱼传尺愫
鱼传尺愫 2020-12-25 14:13

How to check if an Element exists, when using Page Objects with webdriver.

So far I am doing it this way.

DefaultPage defaultPage = PageFactory.initE         


        
8条回答
  •  悲哀的现实
    2020-12-25 14:38

    Arquillian has implemented that feature in Graphene extension.

    Check ElementLocatorConditionFactory.isPresent() function.

    They more or less do what you wrote in your question (from ExpectedConditions.findElement in selenium-support.jar) :

    try {
        return driver.findElement(by);
    } catch (NoSuchElementException e) {
        throw e;
    } catch (WebDriverException e) {
        // [...] some log
        throw e;
    }
    

提交回复
热议问题