The API webdriver.getPageSource() doesn't return HTML tags for plain text file
For Selenium v2.48.2 in conjunction with Firefox browser only, calling the API webdriver.getPageSource() doesn't return any HTML tags. I've confirmed this is only happening with Firefox (v40.0.2, v41.0, v41.0.2, v42.0), and it is NOT happening when tested using Selenium v2.47.0.
There is also no issue with ChromeDriver v2.20 w/Chrome browser or IEDriverServer v2.48.0 w/IE browsers.
I believe this is a subtle/edge case because I'm only seeing this with plain text files, specifically a HOSTINFO.txt file. I do get HTML tags when I hit www.google.com (but do I get them all?).
Code snippet being run -
webdriver.get("file:////HOSTINFO.txt");
String source = webdriver.getPageSource();
where HOSTINFO.txt contains -
"Installed on prod-c4-agrippa-3d927b8d at Mon Nov 02 17:26:36 UTC 2015
AppVersion: 20.9.0-1
DeployTag: agrippa-ops-1.954
Candidate: false"
when I inspect the page using Firefox->Tools->Inspector or Firebug I see basic html/body/pre tags -
Installed on prod-c4-agrippa-3d927b8d at Mon Nov 02 17:26:36 UTC 2015 AppVersion: 20.9.0-1 DeployTag: agrippa-ops-1.954 Candidate: false
In the console of Inspector, I get the following error (but not in the console of Firebug) -
"The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature."
This leads me to suspect that there has been a very subtle change that is causing this to happen.
why would a plain txt file be expected to return HTML tags? It's not HTML.
In general, I agree with you, but I'm not an HTTP protocol expert. The issue is that prior to Selenium v2.48.2 calls to getPageSource() did return html tags from the server. Also, ChromeDriver and IEDriverServer both do as well and still do. This is an inconsistency that surfaced in some of our automation were we need to examine the information returned from the HOSTINFO file and have parsed the returned data based on the presence of the html tags. I'm simply noting there is a difference in behavior between Selenium v2.48.2 and prior releases and wondering if this was by design or unintentional?
In general, I agree with you, but I'm not an HTTP protocol expert.
This has nothing to do with HTTP whatsoever.
The issue is that prior to Selenium v2.48.2 calls to getPageSource() did return html tags
I'd consider the old behavior to be a bug, although opening text files via the browser is an unspecified use-case, so the expected behavior is unspecified also.
ChromeDriver and IEDriverServer both do as well and still do.
I'd consider that behavior to be a bug (with the browsers, not selenium).
we need to examine the information returned from the HOSTINFO file and have parsed the returned data based on the presence of the html tags.
using getPageSource() to read and parse content from a text file is a pretty ridiculous. Just open the text file explicitly, and read it. There's no need leverage a web browser or WebDriver method for that.