Scenario : Launch http://www.flipkart.com. Hover the mouse on the tab named 'ELECTRONICS' and select the option 'Lenovo Yoga Tablet 2' from the menu.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class MouseHover {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://www.flipkart.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// The element on which to mouse hover
WebElement we = driver.findElement(By
.xpath("//a/span[text()='Electronics']"));
Actions act = new Actions(driver);
act.moveToElement(we).perform();
// The element to be selected from drop down
WebElement we1 = driver
.findElement(By.linkText("Lenovo Yoga Tablet 2"));
we1.click();
// act.moveToElement(we1).click().build().perform();
// Even this will work instead of we1.click()
Thread.sleep(5000L);
driver.quit();
}
}
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class MouseHover {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://www.flipkart.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// The element on which to mouse hover
WebElement we = driver.findElement(By
.xpath("//a/span[text()='Electronics']"));
Actions act = new Actions(driver);
act.moveToElement(we).perform();
// The element to be selected from drop down
WebElement we1 = driver
.findElement(By.linkText("Lenovo Yoga Tablet 2"));
we1.click();
// act.moveToElement(we1).click().build().perform();
// Even this will work instead of we1.click()
Thread.sleep(5000L);
driver.quit();
}
}
Pay It
Forward...
Lots
of energy ..
DR
No comments:
Post a Comment