Attempting to execute a javascript function I created to gather all comments from an HTML site using xpath (requirement).
The function, when pasted directly into a browser without the 'return' statement, works flawlessly.
However, when run through the selenium 'javascriptexecutor', it returns an empty array.
I understand that javascript statements need to be enclosed in a " code "+ format, but for clarity purposes, I structured my code like this.
Hoping someone can assist me with this issue :)
ChromeDriver driver = new ChromeDriver();
String url = "AprivateSamplePage";
driver.get(url);
JavascriptExecutor js = (JavascriptExecutor) driver;
String text = (String) js.executeScript("return nodes =[];
xPathResult=document.evaluate('//comment()',document,null,XPathResult.ANY_TYPE, null);
nodes =[];
node = xPathResult.iterateNext();
while (node) {nodes.push(node.textContent);
node = xPathResult.iterateNext();}
nodes;").toString();
System.out.print(text);
The Output appears as follows:
Only local connections are allowed.
Okt 30, 2018 8:56:07 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Detected dialect: OSS
[]
Process finished with exit code 0