I am currently using https://github.com/admc/wd/blob/master/doc/api.md Selenium web driver to test website. I want to simply to check if my view is on the top of the whole screen.
I have attempted to use isDisplay()
and getLocationInView
to serve such purpose.
However, they are either available as absolute position of the element or display in term of element and html page level, instead of actual view itself.
I also tried execute()
eval()
to run JavaScript to capture window then evaluation its axis value, since Selenium is running a real browser (Chrome).
i.e.
...execute("window", function(error, result) { console.log(result) };
...execute("console.log(window)", function(error, result) { console.log(result) };
...execute("return window", function(error, result) { console.log(result) };
However, I was only able to get null
out of the result from these statement.
I think I must have missed a function (even though I read through their API doc more than 3 times).
I thought trigger JavaScript variable inside the testing browser, run a quick func to get axis value, and save it into a var is a viable solution.
However, I was not even able to find a working solution to just getting the window
global var. (yes, after looked at all the relevant post indicate about executing js with selenium)
*Note and yes executeScript
is no longer available, as least for the Selenium I am working with right now (latest version according to my package.json).
*Also important note:
I use wd.js
as the web drive
https://github.com/admc/wd
Alllrighty. I found the solution! Its pretty straight forward. I think it was just because
wd.js
using promise chain at all time, so I am not able to output anything with just eval, but I have to add asserter. so following worked perfectly.if you want to see what's the value in
window.pageYOffset
just fail it manually.Take me two days to understand this thing. Hopefully it save your time as well.