I am facing the following issue, while executing javascript from the PhantomJS Driver using serenity framework.
(PhantomJSDriver) driver).executeScript("document.getElementsById('whereOut')")
Error:
{"errorMessage":"'undefined' is not a function (evaluating 'document.getElementsById('whereOut')')","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"69","Content-Type":"application/json; charset=utf-8","Host":"localhost:33819","User-Agent":"Apache-HttpClient/4.3 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"script\":\"document.getElementsById(\u0027whereOut\u0027)\",\"args\":[]}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/b0246730-4435-11e6-b64c-7bf1e13a7577/execute"}} Command duration or timeout: 278 milliseconds
Also tried following code:
((JavascriptExecutor) driver).executeScript("document.getElementById('whereOut')")
above code returns a null value even if I add a return value as shown below:
((JavascriptExecutor) driver).executeScript("return document.activeElement")
Returns a null value.
Has anyone tried to change the css
of a particular element using phantom js?
((JavascriptExecutor) driver).executeScript("document.getElementById('whereOut').className=''")
What I figured out is that while executing above line of code, I don't get the element using javascript
execution while the same element is retrievable using pure selenium code with firefox browser.
P.S. I am using phantomJS 1.9.7 version along with serenity: 1.0.56.