I have a split page, with a scrollable "form" of label/value pairs on the top and a grid on the bottom. When I try to click a link in the scrollable form section which is currently scrolled out of view, Selenium quietly ignores the click action and nothing happens. How can I force it to click?
Selenium expects the link to be “visible to the end user” before you can actually click on it. In this case the link is actually scrolled out of the view even though it’s inside of the browser's viewport. There are 2 ways to click on this link: use a javascript click method or make the link to be scrolled into the view and then click on it using regular WebElement.click() method.
public void clickHiddenLink() {
String xpathExtComp = ".//*[@name='TargetFieldName' and starts-with(@id, 'ext-comp-')]";
String id = tab.getDriver().findElement(By.xpath(xpathExtComp)).getAttribute("id");
String script = "var c = Ext.getCmp('%s'); var d = c.findParentByType('form').body.dom; d.scrollTop = d.scrollHeight - d.offsetHeight;";
((JavascriptExecutor) tab.getDriver()).executeScript(String.format(script, new Object[] {id}));
tab.getFieldByName("TargetFieldName").getEl().findElement(By.tagName("a")).click();
}