Selenium: Check for the presence of element

前端 未结 5 549
梦谈多话
梦谈多话 2020-11-30 15:14

In real-time automation, do we check for the presence of every element(in test) before performing some action on them?

Wherever there is a findElement

5条回答
  •  眼角桃花
    2020-11-30 15:17

    You may find the use of the class AbstractWebDriverEventListener particularly useful. This class implements the interface WebDriverEventListener which defines before and after hooks for the events triggered by WebDriver.

    One such before hook beforeFindBy could be implemented to check the presence of element. For example:

    public void beforeFindBy(By by, WebElement element, WebDriver driver) {
        // Explicit wait to check for the presence of the element using the "by" locator
    }
    

    Similarly the before hook beforeClickOn could be implemented to check that the element is clickable before the click event is performed on that element.

提交回复
热议问题