How to check if an element is visible with WebDriver

后端 未结 11 1578
臣服心动
臣服心动 2020-12-04 13:14

With WebDriver from Selenium 2.0a2 I am having trouble checking if an element is visible.

WebDriver.findElement returns a WebElement<

11条回答
  •  囚心锁ツ
    2020-12-04 14:01

    public boolean isElementFound( String text) {
            try{
                WebElement webElement = appiumDriver.findElement(By.xpath(text));
                System.out.println("isElementFound : true :"+text + "true");
            }catch(NoSuchElementException e){
                System.out.println("isElementFound : false :"+text);
                return false;
            }
            return true;
        }
    
        text is the xpath which you would be passing when calling the function.
    the return value will be true if the element is present else false if element is not pressent
    

提交回复
热议问题