Selenium : How to use Javascript to show button or move a window.

I had some trouble lately with some Angular interface. So hereĀ  interesting work around I found.

Scenario 1 : You haveĀ  a list of checkbox to click, they are not hidden but hidden under an other element. Like hidden behind a pop-up window or a menu button, but they should partially visible for a human user.
The work around : move the checkbox to a visible position in the page. How?

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", checkBoxElement);

Scenario 2 : You want to move a Pop-up window using Javascript by using the position.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', 'top: 0px');", windowElement);

Leave a Reply