Selenium webdriver can't click on a link outside the page Selenium webdriver can't click on a link outside the page selenium selenium

Selenium webdriver can't click on a link outside the page


It is actually possible to scroll automatically to element. Although this is not a good solution in this case (there must be a way to get it working without scrolling) I will post it as a workaround. I hope someone will come up with better idea...

public void scrollAndClick(By by){   WebElement element = driver.findElement(by);   int elementPosition = element.getLocation().getY();   String js = String.format("window.scroll(0, %s)", elementPosition);   ((JavascriptExecutor)driver).executeScript(js);   element.click();}


I posted this same answer in another question so this is just a copy and paste.

I once had a combo box that wasn't in view that I needed to expand. What I did was use the Actions builder because the moveToElement() function will automatically scroll the object into view. Then it can be clicked on.

WebElement element = panel.findElement(By.className("tabComboBoxButton"));Actions builder = new Actions(this.driver);builder.moveToElement(element);builder.click();builder.build().perform();

(panel is simply a wrapped element in my POM)


Instead of move the scrollbar to the button position, which sometimes it didn't work for me, I send the enter key to the button

var element = driver.FindElement(By.Id("button"));element.SendKeys(Keys.Enter);