I am attempting to have selenium click on links, which are within li elements. This is happening inside a while loop. The clicks are working until I reach an li which is below the level of the Firefox window. If I manually scroll down in the Firefox webdriver window before selenium attempts the click, the click will work without error.
Here is the java code I'm using for the click. Menu_item_module is an int which increases by 1 each time the loop runs to move down the list. The webelement below references the li element.
driver.findElement(By.id("digitalVellum_dijit_MenuListItem_" + menu_item_module)).click();
Here is a code snippet containing one of the li elements from the page in question.
<li id="digitalVellum_dijit_MenuListItem_11" class="dijitLayoutContainer dijitContainer menuListItem level1 item-22 closed dijitLayoutContainer-child dijitLayoutContainer-dijitLayoutContainer" data-dojo-attach-event="onclick:click" data-dojo-attach-point="containerNode" widgetid="digitalVellum_dijit_MenuListItem_11">
<a href="#" data-dojo-attach-point="_link" tabindex="0">
<span class="expander" data-dojo-attach-event="onclick:_toggleState"></span>
<span class="label">Overview</span>
<div class="clearoutfloats"> </div>
</a>
<ul id="digitalVellum_dijit_MenuList_2" class="mainMenu dijitLayoutContainer dijitContainer dijitLayoutContainer-child dijitLayoutContainer-dijitLayoutContainer" data-dojo-attach-point="containerNode" widgetid="digitalVellum_dijit_MenuList_2">
</li>
I have tried to have selenium scroll by using the following code.
JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0,100)", "");
This appears to have no effect. I think that may be because the scroll area is a frame, not the entire page. Regardless, I didn't think I should need to scroll at all. I thought webdriver will scroll automatically when necessary to select an element.
Any help or insight would be much appreciated.
Thanks, Steve Archibald
driver.switchTo().frame("frameIdentifier")
before you'll be able to access elements in that frame. – Richarddriver.manage().window.maximize();
and then try the click. – Faiz