normalize space not parsing correctly under some circumstances
See original GitHub issueI am using an xpath that includes a special character and the xpath is working in Firefox but failing in HtmlUnit when called via the driver.
What is odd is that it works for “@x” but fails for “@X” - case sensitivity breaks it somehow. Its also interesting that I noticed this earlier when searching for “=)” as part of a string, I presume there are other special cases that are not working correctly.
Edit: tested more and same issue with “)X” but lowercase x works fine.
The code I used to test
public class HtmlUnitXpath {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
WebDriver ffDriver = new FirefoxDriver(options);
WebDriver huDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX, true) {
@Override
protected WebClient modifyWebClient(WebClient client) {
final WebClient webClient = super.modifyWebClient(client);
WebClientOptions options = webClient.getOptions();
options.setCssEnabled(true);
options.setThrowExceptionOnScriptError(false);
webClient.setJavaScriptErrorListener(new SilentJavaScriptErrorListener());
return webClient;
}
};
try {
doStuff(ffDriver);
doStuff(huDriver);
} finally {
ffDriver.close();
huDriver.close();
}
}
private static void doStuff(WebDriver driver) {
String misbehavingString = "@X";
String pageAsText = "<body><table><tr><td>" + misbehavingString + "</td></tr></table></body>";
driver.get("data:text/html;charset=utf-8," + pageAsText);
String text = driver.findElement(By.xpath("//body")).getText();
System.out.println(driver.getClass().getName() + " printed " + text);
int numberOfOccurences = driver.findElements(By.xpath("//td[normalize-space()='" + misbehavingString + "']")).size();
System.out.println(driver.getClass().getName() + " found " + numberOfOccurences);
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
normalize-space just works with xpath not css selector
Unfortunately, XPath functions are not available with CSS selectors in Scrapy. You could first translate your div[class=location]::text CSS ...
Read more >How normalize-space Function Work in XSLT? - eduCBA
This is a guide to XSLT normalize-space. Here we discuss the introduction, how normalize-space function work in XSLT? and examples.
Read more >normalize-space - XPath - MDN Web Docs
The normalize-space function strips leading and trailing white-space from a string, replaces sequences of whitespace characters by a single ...
Read more >Advanced Xpath Concept - Method normalize-space & Its Usage
Hello Folks,. In this post we will going to learn an advanced concept of xpath: – normalize-space method. Before we discuss about method ......
Read more >XML Normalization - W3C
The normalized form of an XML document may not be completely operational within the application context, though the circumstances under ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
nice catch - found the reason and start thinking about a solution
Yeah, I always try to imagine if it was me doing the bug testing and fixing, the more info I have the faster I can fix it. Plus shows I at least tried to find the cause instead of pasting a generic error code and asking for help.