1

I want to click on element from a list but the problem is that, the element is present in list but due to huge size of that list required element is not visible on page (Current frame). To click on required element I have to scroll down the list then that element get visible.

please suggest me how to do that. I am using Selenium Webdriver using Ruby.

  • Maybe this topic will help http://stackoverflow.com/questions/12035023/selenium-webdriver-cant-click-on-a-link-outside-the-page – JacekM Jun 06 '13 at 14:45
  • What kind of list do you mean? Is it a drop-down list (an html ` – Vince Bowdren Jun 06 '13 at 16:51
  • No it is not drop down list. It is simple list which contains 30-35 options or links but due to large size of list my intended element is getting hide on current displaying page. to see that element I have scroll down the page then my element is getting display. – Sidram Waghmare Jun 07 '13 at 06:42

4 Answers4

1

You can try this,
capture element's xpath (or By id whatever you think is right) when it is visible
and click on it using js
Here I want to click Sign Out which come visible in a drop down menu only on mouse hover.

WebElement hiddentElement = driver.findElement(By
                                .xpath("//*[@id='navright']/li[3]/ul/li[2]/a"));
                ((JavascriptExecutor) driver).executeScript("arguments[0].click();",
                                hiddentElement);
paul
  • 4,333
  • 16
  • 71
  • 144
0

Selenium is supposed to imitate the user behaviour, clicking on invisible elements isn't supported by default for that reason.

You will probably end up with an exception for doing that.

Ittiel
  • 1,104
  • 9
  • 12
0

You can use the method getLocationOnScreenOnceScrolledIntoView to make WebDriver scroll the element into view:

if (element instanceof Locatable) {
    Locatable remoteElement = (Locatable) inputElement;          
    remoteElement.getLocationOnScreenOnceScrolledIntoView();
}
Community
  • 1
  • 1
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
0

Used the below solution once in a similar situation and it worked for me. Basically get all the elements of the list and using Actions iterate through each one and get the text and if it is the required option then click on it using Actions class again.

Akbar
  • 1,513
  • 4
  • 20
  • 34