We can open the browser by using get("") a non-static method present in the FirefoxDriver class, it accepts a string as arguments, and the string should be the website address.
A special thing about this get("") method is it will not give control to the next line till the page loads completely.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class OpenWebSite
{
public static void main(String[] args) throws Exception
{
WebDriver driver=new FirefoxDriver();
// tries to open chercher.tech page
driver.get("chercher.tech");
}
}
Did you able to open Google. If the answer is nope means why ?
Did you get the following error ?
Exception in thread "main" org.openqa.selenium.WebDriverException: f.QueryInterface is not a function Command duration or timeout: 94 milliseconds
Solution:
Whenever we pass the website address to the get() method. It first of checks for the protocol in the address, but in the above program, we did not mention any the protocol.
What is the protocol ?
The Protocol is simple; it mentions what kind of site is that.
Example for protocol:
Let's edit the above program
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class OpenSite
{
public static void main(String[] args) throws Exception
{
WebDriver driver=new FirefoxDriver();
// tries to open https://chercher.tech page
driver.get("https://chercher.tech");
}
}
Let us take the below scenario.
I do not have an Internet connection, but I saved some webPages on my computer, is it possible for me to work in selenium ?
The answer is YES; you can like below.
Open the saved webpage in a browser and copy the address in the address bar, this will have a protocol as the file it looks something like below
file:///C:/Users/path/selenium.html
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class OpenSite
{
public static void main(String[] args) throws Exception
{
WebDriver driver=new FirefoxDriver();
// opens the file like real page
driver.get("file:///C:/Users/path/selenium.html");
}
}
Note: If the site does not have the protocol, then just copy-paste the URL into eclipse, it will automatically import the protocol.
Hybrid Inheritance in Java and Selenium
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.
Sprint Section : Spelling mistake of testcase preparation : estcase preparation
Thanks, Sandeep,. We will correct it
1. Kindly provide next and previous link to move one page to another page. 2. Kindly provide a link at the bottom of the each page by clicking link I can go to the top without scrolling. Above both scenarios will make site more user friendly. Other than this I liked your website most.
Hi Nishanth, We have incorporated the second point, but for first point it will take little more time.