如何使用 Selenium 和 Java 在浏览器自动化中找到准确的文本?

问题描述 投票:0回答:1
java selenium xpath css-selectors webdriverwait
1个回答
1
投票

要提取字符串不再有等待授权的候选人,您不需要这样的循环。由于该元素是 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");
    
© www.soinside.com 2019 - 2024. All rights reserved.