Hi,
I am tring to print all mobile names and there prices and write to excel sheet, how can i print for all pages i am only able to print for single page.
Here is my code:
package POI;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class flipkart {
public static void main(String[] args)throws Exception {
System.setProperty("webdriver.chrome.driver","E:\\selenium driver\\ChromeDriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.findElement(By.cssSelector("input[class='_2IX_2- VJZDxU'][type='text']")).sendKeys("7842232997");
//driver.findElement(By.xpath("(//input[@type='text'])[2]")).sendKeys("");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("");
Thread.sleep(2000);
driver.findElement(By.xpath("(//button[@type='submit'])[2]")).click();
Thread.sleep(2000);
//click on mobile
//driver.findElement(By.cssSelector("#container div:nth-child(3) div.xtXmba")).click();
driver.findElement(By.xpath("//div[text()='Mobiles']")).click();
Thread.sleep(2000);
//electronics
WebElement Ele=driver.findElement(By.cssSelector("._1kidPb span:nth-child(1)"));
//Xpath-//span[text()='Electronics']
Actions Act=new Actions(driver);
Act.moveToElement(Ele).perform();
Thread.sleep(3000);
driver.findElement(By.linkText("Samsung")).click();
Thread.sleep(2000);
//click on view all
driver.findElement(By.xpath("(//span[text()='VIEW ALL'])[1]")).click();
Thread.sleep(2000);
//price high to low
//xpath= //div[@class='_5THWM1']/div[contains(text(),'Price -- High to Low')]
//driver.findElement(By.cssSelector("._10UF8M._3LsR0e"));
driver.findElement(By.xpath("//div[@class='_5THWM1']/div[contains(text(),'Price -- High to Low')]")).click();
Thread.sleep(3000);
//mobile name
List<WebElement> web = driver.findElements(By.className("_4rR01T"));
System.out.println(web.size());
//print all links names using for each loop
for(WebElement E: web)
{
System.out.println(E.getText());
}
//price
List<WebElement> web2 = driver.findElements(By.xpath("//div[@class='_30jeq3 _1_WHN1']"));
System.out.println(web2.size());
//print all links names using for each loop
for(WebElement E1: web2)
{
System.out.println(E1.getText());
}
driver.close();
driver.quit();
}
}
output-
24
SAMSUNG Galaxy Fold 2 (Mystic Bronze, 256 GB)
SAMSUNG Galaxy Fold 2 (Mystic Black, 256 GB)
SAMSUNG Galaxy S10 Plus (Ceramic White, 1 TB)
SAMSUNG Galaxy S21 Ultra (Phantom Black, 256 GB)
SAMSUNG Galaxy S21 Ultra (Phantom Silver, 256 GB)
SAMSUNG Galaxy Note 20 Ultra 5G (Mystic Bronze, 256 GB)
SAMSUNG Galaxy Note 20 Ultra 5G (Mystic Black, 256 GB)
SAMSUNG Galaxy Note 9 (Ocean Blue, 512 GB)
SAMSUNG Galaxy S10 (Prism White, 512 GB)
SAMSUNG Galaxy S10 Plus (Ceramic Black, 512 GB)
SAMSUNG Galaxy Note 9 (Midnight Black, 512 GB)
SAMSUNG Galaxy S20 Ultra (Cosmic Gray, 128 GB)
SAMSUNG Galaxy S21 Plus (Phantom Violet, 256 GB)
SAMSUNG Galaxy S21 Plus (Phantom Silver, 256 GB)
SAMSUNG Galaxy S21 Plus (Phantom Black, 256 GB)
SAMSUNG Galaxy S21 Plus (Phantom Silver, 128 GB)
SAMSUNG Galaxy S21 Plus (Phantom Black, 128 GB)
SAMSUNG Galaxy S21 Plus (Phantom Violet, 128 GB)
SAMSUNG Galaxy Note 20 (Mystic Blue, 256 GB)
SAMSUNG Galaxy Note 20 (Mystic Bronze, 256 GB)
SAMSUNG Galaxy Note 20 (Mystic Green, 256 GB)
SAMSUNG Galaxy S21 (Phantom Violet, 256 GB)
SAMSUNG Galaxy S21 (Phantom White, 256 GB)
SAMSUNG Galaxy Note 9 (Ocean Blue, 128 GB)
24
?1,49,999
?1,49,999
?1,17,990
?1,05,999
?1,05,999
?1,04,999
?1,04,999
?93,000
?92,000
?91,900
?88,030
?86,999
?85,999
?85,999
?85,999
?81,999
?81,999
?81,999
?77,999
?77,999
?77,999
?75,999
?73,999
?73,645