Friday 21 March 2014

Random

WebDriver driver=new FirefoxDriver();
driver.get("http://www.donebynone.com/?gclid=CLXXyPaikb0CFedV4godlE0Azw");
driver.manage().window().maximize();

Random randomGenerator = new Random();
java.util.List<WebElement> ll=driver.findElements(By.xpath("html/body/header/div[4]/div[1]/nav/section/ul/li"));
int la=ll.size();
System.out.println(la);
int ran1=randomGenerator.nextInt(la)+1;

System.out.println("ran1..."+ran1);
java.util.List<WebElement> l=driver.findElements(By.xpath("html/body/header/div[4]/div[1]/nav/section/ul/li[1]/ul/li[2]"));
int a=l.size();


System.out.println("szeTwo"+la);
System.out.println("szeOne"+a);

int ran2=randomGenerator.nextInt(a)+3;

System.out.println("ran2..."+ran2);
WebElement web=driver.findElement(By.xpath("html/body/header/div[4]/div[1]/nav/section/ul/li["+ran1+"]/ul/li["+ran2+"]/a"));
// WebElement web=driver.findElement(By.xpath("html/body/header/div[4]/div[1]/nav/section/ul/li[5]/ul/li[4]/a"));
WebElement web1=driver.findElement(By.xpath("html/body/header/div[4]/div[1]/nav/section/ul/li[1]"));
//WebElement web=driver.findElement(By.xpath("html/body/header/div[4]/div[1]/nav/section/ul/li[5]/ul/li[4]/a"));
Actions act=new Actions(driver);
act.moveToElement(web1).build().perform();
Thread.sleep(5000);
web.click();
System.out.println("over");