要提取字符串不再有等待授权的候选人,您不需要这样的循环。由于该元素是 Angular 元素,因此您需要引发 WebDriverWait 并且可以使用以下任一解决方案:
CssSelector
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.ng-scope[data-ng-if*='newRequestReceived'] p.ng-scope[data-ng-if*='authRequestCount']"))).getAttribute("innerHTML");
XPath
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='ng-scope' and contains(@data-ng-if,'newRequestReceived')]//p[@class='ng-scope' and contains(@data-ng-if,'authRequestCount')]"))).getAttribute("innerHTML");