Hello Folks,
We have learnt how to open Chrome, Firefox, IE and Edge browser. It is very first step before we start automating test cases through Selenium Webdriver.
Second step is to load URL of AUT(Application Under Test). So in this post we will learn below topics:
Most common way of loading a URL in browser in Selenium is using get() method.
Syntax: void get(java.lang.String url)
Points to know about get():
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
14. You can not go back and forward using get() method. You can use get() multiple times in a program.
Complete JAVA Program:
package MakeSeleniumEasy;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoadURL {
public static void main(String[] args) {
System.out.println("Execution Starts");
// Setting chrome driver property and opening chrome browser
System.setProperty("webdriver.chrome.driver", "./exefiles/chromedriver.exe");
WebDriver driver= new ChromeDriver();
System.out.println("Browser opened.");
// loading URL
driver.get("http://makeseleniumeasy.com");
System.out.println("makeseleniumeasy loaded");
driver.get("http://www.facebook.com");
System.out.println("Facebook loaded.");
// Setting default page load time. It will be applicable from next line not for above code
driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.SECONDS);
driver.get("http://www.learn-automation.com");
}
}
Output:
In above program, I am setting page load time once Facebook is loaded. New page load time will be applicable from next statement. Remember execution of JAVA programs goes line by line. I am setting less page load time to get exception.
public void to(String url)
{
RemoteWebDriver.this.get(url);
}
Complete JAVA Program:
package MakeSeleniumEasy;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoadURLUsingTo {
public static void main(String[] args) {
System.out.println("Execution Starts");
// Setting chrome driver property and opening chrome browser
System.setProperty("webdriver.chrome.driver", "./exefiles/chromedriver.exe");
WebDriver driver= new ChromeDriver();
System.out.println("Browser opened.");
// loading URL
driver.navigate().to("http://makeseleniumeasy.com");
System.out.println("makeseleniumeasy loaded");
driver.get("http://www.facebook.com");
System.out.println("Facebook loaded.");
driver.navigate().back();
System.out.println("Back: "+driver.getCurrentUrl());
driver.navigate().forward();
System.out.println("Forward :"+driver.getCurrentUrl());
driver.navigate().refresh();
System.out.println("Refresh: "+driver.getCurrentUrl());
}
}
Output:
Difference between get() and navigate():
That’s it guys. I hope you must have learnt some new things. If you have any doubt or suggestions, feel free to contact me.
Thank you.
#HappyLearning
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning
Hello Folks, As part of our API Testing series, we will see "Introduction of Postman Tool" in this post. Postman is…
Hello Folks, As part of our API Testing series, we will see "Tools to test SOAP and REST APIs manually and…
Hello Folks, As part of our API Testing series, we will see "Difference between SOAP and REST web services" in…
Hello Folks, As part of our API Testing series, we will see “Introduction of SOAP” in this post. SOAP stands…
Hello Folks, Most of us we know that to handle a dropdown developed using Select tag, we can use inbuilt…
Hello Folks, In this post we will going to learn an advanced concept of xpath: - normalize-space method. Before we discuss…