Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html XPath text/replace查找可能包含软连字符的文本_Html_Selenium_Selenium Webdriver_Xpath_Soft Hyphen - Fatal编程技术网

Html XPath text/replace查找可能包含软连字符的文本

Html XPath text/replace查找可能包含软连字符的文本,html,selenium,selenium-webdriver,xpath,soft-hyphen,Html,Selenium,Selenium Webdriver,Xpath,Soft Hyphen,搜索文本:BescheinigungenMyXPath还应返回包含软连字符的元素,如:Beschei\u00ADnigungen 我试过这个: //*[text()[replace(., "\u00AD", "")="Bescheinigungen"]] 不起作用。需要一些帮助。好的,必须使用一些“帮助者”代码才能工作: public static WebElement findByText(WebDriver driver, Str

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

我试过这个:

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

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

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

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);
}
publicstaticwebelement findByText(WebDriver驱动程序,字符串文本){
List elements=driver.findElements(By.xpath(“/*[text()]”);
返回elements.stream().filter(元素->{
字符串elementText=element.getText();
if(elementText!=null&&!elementText.isEmpty()){
返回text.equals(elementText.replace(“\u00AD”,”);
}
返回false;
}).findFirst().OrelsThrow(NotFoundException::new);
}