//Click mobiles and it's looping the name
import java.awt.AWTException;
import java.util.List;
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 Cart_Content_Print_Name {
public static void main(String[] args) throws AWTException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://shopping.rediff.com/shopping/index.html");
WebElement mobiles = driver.findElement(By.xpath("//span[text()='Mobiles']"));
Actions act = new Actions(driver);
act.moveToElement(mobiles).perform();
act.moveToElement(driver.findElement(By.xpath("//a[text()='Mobile Handsets']"))).click().perform();
List<WebElement> sets = driver.findElements(By.xpath("//div[@class='div_grid_display_big']"));
for(int i=0; i<3; i++){
sets.get(i).findElement(By.tagName("a")).click();
driver.findElement(By.xpath("//input[@value='Buy now']")).click();
if(i<2){
driver.get("http://shopping.rediff.com/categories/mobile-handsets--new-/cat-8344/?sc_cid=fixcat_mobile%20handsets");
sets = driver.findElements(By.xpath("//div[@class='div_grid_display_big']"));
}
}
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='cartframe']")));
List<WebElement> cart = driver.findElements(By.xpath("//tr[@class='selected_graybg']//table[@style='width:800px;padding:8px 0px 0px 0px;']"));
for(int j=0; j<cart.size(); j++){
List<WebElement> rowstest=cart.get(j).findElements(By.tagName("tr"));
for(WebElement r:rowstest)
{
List<WebElement> cols=r.findElements(By.tagName("td"));
for(int k=0; k<cols.size(); k++)
{
if(k==0){
System.out.print(cols.get(k).findElement(By.tagName("a")).getText()+" ");
}else if(k==1){
System.out.print(cols.get(k).findElement(By.tagName("input")).getAttribute("value")+" ");
}else{
System.out.print(cols.get(k).getText()+" ");
}
}
System.out.println();
}
}
}
}
import java.awt.AWTException;
import java.util.List;
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 Cart_Content_Print_Name {
public static void main(String[] args) throws AWTException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://shopping.rediff.com/shopping/index.html");
WebElement mobiles = driver.findElement(By.xpath("//span[text()='Mobiles']"));
Actions act = new Actions(driver);
act.moveToElement(mobiles).perform();
act.moveToElement(driver.findElement(By.xpath("//a[text()='Mobile Handsets']"))).click().perform();
List<WebElement> sets = driver.findElements(By.xpath("//div[@class='div_grid_display_big']"));
for(int i=0; i<3; i++){
sets.get(i).findElement(By.tagName("a")).click();
driver.findElement(By.xpath("//input[@value='Buy now']")).click();
if(i<2){
driver.get("http://shopping.rediff.com/categories/mobile-handsets--new-/cat-8344/?sc_cid=fixcat_mobile%20handsets");
sets = driver.findElements(By.xpath("//div[@class='div_grid_display_big']"));
}
}
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='cartframe']")));
List<WebElement> cart = driver.findElements(By.xpath("//tr[@class='selected_graybg']//table[@style='width:800px;padding:8px 0px 0px 0px;']"));
for(int j=0; j<cart.size(); j++){
List<WebElement> rowstest=cart.get(j).findElements(By.tagName("tr"));
for(WebElement r:rowstest)
{
List<WebElement> cols=r.findElements(By.tagName("td"));
for(int k=0; k<cols.size(); k++)
{
if(k==0){
System.out.print(cols.get(k).findElement(By.tagName("a")).getText()+" ");
}else if(k==1){
System.out.print(cols.get(k).findElement(By.tagName("input")).getAttribute("value")+" ");
}else{
System.out.print(cols.get(k).getText()+" ");
}
}
System.out.println();
}
}
}
}
No comments:
Post a Comment