3. WEB DRIVER METHODS:
Abhishek Chauhan
Senior Software Quality Assurance Engineer at Policybazaar.com | Senior Automation Engineer | Selenium | Java | Postman | MySQL |Jira | Logs | Web testing | Mobile Testing| GA |
Methods of WebDriver Interface:
1 get() To enter the url
2 getTitle() To get the title of current web page
3 getCurrentUrl() To get the url of current web page
4 getPageSource() To get the page source of current web page
5 findElement() To get single webElements
6 findElements() To get multiple webElements
7 getWindowHandle() To get the id of parent window
8 getWindowHandles() To get the id of All windows
9 switchTo() Used to switch one window to other window
10 manage()
1. Window 2. Cookies
11 navigate()
领英推荐
1. Enter the URL 2. Navigate to previous page
3. Navigate to next page 4. Refresh current web page
12 close() To close the current/parent browser
13 quit() To close all the browsers opened by selenium
NAVIGATION COMMANDS:
1. Navigate().to()
2. Refresh()
3. Back()
4. Forword()
public class Demo
{
public static void main(String[] args) throws InterruptedException
{
//open the browser
System.setProperty("webdriver.chrome.driver",
"./drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
//enter the url
driver.get("https://www.google.com/");
//To get the title of current web page
String title = driver.getTitle();
System.out.println("Title: "+title);
//To get the url of current web page
String url = driver.getCurrentUrl();
System.out.println("URL: "+url);
//To close the browser
Thread.sleep(2000);
driver.close();
}
}
// Open the browser
//Delete all cookies
//Set size of the window
//Set position of the window
//Maximize the window
public class Demo
{
public static void main(String[] args) throws InterruptedException
{
//To open the browser
System.setProperty("webdriver.chrome.driver",
"./drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
Thread.sleep(2000);
//To delete cookies
driver.manage().deleteAllCookies();
//To set the size of the window
Dimension d = new Dimension(500, 500);
driver.manage().window().setSize(d);
Thread.sleep(2000);
//To set the position of the window
Point p = new Point(250, 250);
driver.manage().window().setPosition(p);
Thread.sleep(2000);
//To maximize the window
driver.manage().window().maximize();
}
}
//NAVIGATION COMMANDS
//1. Navigate().to()
//2. Refresh()
//3. Back()
//4. Forword()
public class Demo
{
public static void main(String[] args) throws InterruptedException
{
//open the browser
System.setProperty("webdriver.chrome.driver",
"./drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
//To maximize the window
driver.manage().window().maximize();
//To delete the cookies
driver.manage().deleteAllCookies();
driver.get("https://www.google.com/");
//To enter the url
driver.navigate().to("https://www.facebook.com/");
Thread.sleep(1000);
//To navigate to previous page
driver.navigate().back();
Thread.sleep(1000);
//To navigate to next page
driver.navigate().forward();
Thread.sleep(1000);
//Refresh current web page
driver.navigate().refresh();
}
}
public class Demo
{
public static void main(String[] args) throws InterruptedException
{
//open the browser
System.setProperty("webdriver.chrome.driver",
"./drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.naukri.com/");
Thread.sleep(2000);
//To close all the browsers
driver.quit();
}
}
JAVA/J2EE Developer
1 年Thankyou Abhishek:)