webElement.text()获取到内容为空

使用webElement.text()方法获取字符串时,有时候会获取失败--获取到的内容为空

lozz的博客

 

使用 webElement.getAttribute("attributeName"),通过textContentinnerTextinnerHTML等属性获取

public String getText(String string){
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement webElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(string)));
        return webElement.getAttribute("innerText");
    }

 

posted @ 2019-07-24 16:13  Lozz  阅读(868)  评论(0编辑  收藏  举报