Thursday 11 June 2015

Working with multiple submenu in selenium webdriver on amazon.in

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 amazon {

public static void main(String[] args) {
WebDriver driver;
String url;

driver = new FirefoxDriver();
driver.manage().window().maximize();
url ="http://www.amazon.in";
driver.get(url);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Actions act = new Actions(driver);

WebElement wele = driver.findElement(By.xpath("//a[@id='nav-link-shopall']"));
act.moveToElement(wele).perform();

WebElement wele1 = driver.findElement(By.xpath("//div[@id='nav-flyout-shopAll']/div/span/span[text()='Car & Motorbike']"));
act.moveToElement(wele1).perform();

WebElement wele2 = driver.findElement(By.xpath("//div[@id='nav-flyout-shopAll']/div/div/div/a/span[text()='All Car & Motorbike']"));
act.moveToElement(wele2).click().perform();
}

}

No comments:

Post a Comment