The below script illustrates the use of action builder class to work on hidden object.
There is no direct approach to work on hidden objects using selenium webdriver, when i mean hidden objects sometimes we drag our mouse over something and we get to see some list which is clickable, these list are not popped up if we click on those links only dragging a mouse over that link will actually display the contents. To work with such kind we need to action builder class.
What Action builder class does? It actually controls mouse movement, first it will go that particular link and trigger mouse left button and without releasing the left button will go that particular content which needs to be clicked.
I have taken example of Flipkart.com where we get to see the various categories of items when we drag our mouse over the categories links.
package com.flipkart;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
public class flipkart {
void click()
{
File file = new File("C:/IE driver/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver d = new InternetExplorerDriver();
d.get("http://www.flipkart.com");
WebElement M = d.findElement(By.xpath(".//*[@id='fk-header-tab-book']/div[1]/a/div/div// maa[1]/div"));//Main menu
WebElement SM=d.findElement(By.xpath(".//*[@id='fk-header-tab-book']/div[2]/div[1]/div/div/ul[1]/li[1]/a"));//hidden dynamic element
Actions builder = new Actions(d);// To hold mouse on menu
builder.moveToElement(M).build().perform();
SM.click();
}
public static void main(String[] args) {
flipkart l= new flipkart();
l.click();//Calling the method
}
}
ReplyDeleteSelenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
Selenium Training Institute in Chennai