I’m using StringUtils from the Apache commons library to check the # of matches of a sub-string within the source code of an HTML page.
I have converted the page source using the WebDriver command:
String pageSource = driver.getPageSource();
The code I’m using to find # of matches is:
int cloudfCount = StringUtils.countMatches(pageSource, “cloudfront”);
System.out.println(“There are ” + cloudfCount + ” instances of cloudf text found within the page source.”);
When I right-click within the page, view source, then Ctrl-F to find CloudFront, I get 2 matches. Which is what I’m expecting.
But when I use the above code in an automated Selenium script, I’m getting 5 results.
Any thoughts/ideas on where I’m going wrong?
Could it somehow be related to the fact, that the CloudFront text is part of 2 JavaScript tags within the page source?