Selenium Webdriver Program

Write a program in Selenium webdriver to check the current page number by total number of pages visible at the bottom of each page in an application. Assume there are 100 pages. Ex: 10/100, 11/100 etc.

Showing Answers 1 - 6 of 6 Answers

Guru

  • Sep 13th, 2016
 

String str=driver.findElement(By.id("someid")).getText();
String arr[]=str.split("/");
System.out.println("The current page number is "+arr[0]);

  Was this answer useful?  Yes

// This program prints 3/75 3 is the current page and 75 is the last
//we just did gettext for both elements and printed
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class CurrentPageTotalPage {
public static void main(String[] args) {
// TODO Auto-generated method stub
// System.out.println(" The current and total pages are " + result);
System.setProperty("webdriver.chrome.driver", "D:\software\chromedriver_win32\chromedriver.exe");
WebDriver drv = new ChromeDriver();
drv.get("http://www.amazon.in/s/ref=sr_pg_3?rh=n%3A976389031%2Ck%3Ashoes&page=3&keywords=shoes&ie=UTF8&qid=1498705578&spIA=1333873328,1332105327,3659770345,1440061440");

WebElement el1 = drv.findElement(By.className("pagnCur"));
WebElement el2 = drv.findElement(By.className("pagnDisabled"));

String result=el1.getText()+ "/" + el2.getText();

System.out.println(" The current and total pages are " + result);
}
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions