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");
    }
原文地址:https://www.cnblogs.com/lozz/p/10297977.html