I am using StringUtils from the apache commons library to check the # of matches of a substring 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 am 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 am expecting.
But when I use the above code in an automated Selenium script, I am 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?
Thank you.
ctrl + f
on the page source given by webdriver and the one in your browser. See the difference. – LittlePanda Apr 20 '15 at 10:14