Friday, June 14, 2013

Locating and element which is SubElement of a Dropdown and becomes visible only when Parent Element is Hovered.

This Scenario is related mainly to Webpages in which we have some dropdown Element and that element comes only when we Place our mouse on that parent Element . On placing/hovering mouse , a dropdown list is visible and we have to click on a particular link. At first , this seems quite simple  and we will start recording the same in IDE and will check if the same is recorded and can be run back. If that happened you are lucky and probably you will never visit this page or google this problem , but in other case you may land on this kind of blog ( may be  on a better one with more desription ..)

So lets start working on this ....

Remember the power of OBJECTS ( here in my case OBJECTS are just WEBELEMENTS ). below is the screen shot for one of the website that has following kind of scenarios.


Sample Website

Now we have to do 2 steps mainly
1 ) Go to parent element and wait for dropdown to be visible
2) Click on the Desired element as soon as the same is visible in dropdown

not wasting your time here , i am pasting code which i used in my case .( Remember the Titans who gave an idea about this thing to me )

                  driver.navigate().to(" ** URL HERE **");
                  WebElement mnEle; // First Element Locator .In Above case Wealth Locator
                  mnEle = driver.findElement(By.xpath("**** Write your Favorite way of Locating Element **"));
                 // Locates first Element and saves it in mnEle
                  Thread.sleep(3000L);
                  Actions builder = new Actions(driver);
                  Thread.sleep(5000L);
                  builder.moveToElement(mnEle).build().perform();
                  Thread.sleep(3000L);
                  // The line below will find the Second Element and clicks on that Image
                  driver.findElement(By.xpath(" ** same thing again *** ")).click();

Hope that Helps ...:) :)
there are some other methods too like using JavaScriptExecutor that will search the element in Document and click on the sub element after Mousehovering first element.






No comments:

Post a Comment