【问题标题】:XPath text/replace to find text which may contain soft-hyphenXPath 文本/替换以查找可能包含软连字符的文本
【发布时间】:2021-02-26 13:03:21
【问题描述】:

搜索文本:Bescheinigungen 我的 XPath 还应该返回包含软连字符的元素,例如:Beschei\u00ADnigungen

我试过了:

//*[text()[replace(., "\u00AD", "")="Bescheinigungen"]]

不起作用。需要一些帮助,请。

【问题讨论】:

    标签: html selenium selenium-webdriver xpath soft-hyphen


    【解决方案1】:

    好的,必须使用一些“帮助”代码才能使其工作:

    public static WebElement findByText(WebDriver driver, String text) {
      List<WebElement> elements = driver.findElements(By.xpath("//*[text()]"));
      return elements.stream().filter(element -> {
        String elementText = element.getText();
        if (elementText != null && !elementText.isEmpty()) {
          return text.equals(elementText.replace("\u00AD", ""));
        }
        return false;
      }).findFirst().orElseThrow(NotFoundException::new);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      • 2018-01-24
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      相关资源
      最近更新 更多