Selenium Webdriver Execution

So far, in selenium automation, we have seen what is web driver and its architecture. Now its time execute the scripts using Web driver.

Aim : 

To verify the user required URL and display the title as an output

working with Firefox browser:

Create a JAVA project “Selenium  tutorial”

and likewise, Create a Package ” selenium test”

Create a JAVA class ” Selenium  driver example”

And Execute the following Code in your IDE

package selenium test;

//Importing packages
//We need to import relevant packages depends on our needs.
import org.openqa.selenium.WebDriver;
//It contains the WebDriver class to instantiate a new browser
import org.openqa.selenium.firefox.FirefoxDriver;
//It contains the FirefoxDriver class to instantiate a Firefox driver

public class Seleniumdriverexample {

public static void main(String[] args) {

//Instantiation of driver object. To launch Firefox browser
WebDriver driver = new FirefoxDriver();
//Declaration of variables
String url = “https://www.onlineitguru.com”;

//Expected title
String expectedTitle = ” Online IT Certification Training | Online Courses | OnlineITGuru”;
String actualTitle = null;

//To oepn URL “https://onlineitguru.com/onlinetutorials/selenium”. This is what we have assigned to the variable named ‘url’.
driver.get(url);
//To get the actual value of the title. getTitle method used to get the page title
actualTitle = driver.getTitle();
//Using if-else condition to compare the Expected Title and Actual Title. As per the below lines of code (if-else condition).
if (actualTitle.contentEquals(expectedTitle)){
//’system.out.println’ prints the output
System.out.println(“Expected Value is “+expectedTitle);
System.out.println(“Actual Value is “+actualTitle);
System.out.println(“Test Passed”);
} else {
System.out.println(“Expected Value is “+expectedTitle);
System.out.println(“Actual Value is “+actualTitle);
System.out.println(“Test Failed”);
}
//’close’ method is used to close the browser window
driver.close();
//To run the script – Go to menu bar – click on Run – Run or use shortcut key Ctrl+F11
//You could see the output in the console as shown below:
//Test Passed
}
}

working with Chrome Driver:

Initially ,  to work with the chrome driver, we need  to download and install the Chrome driver. You can easily download the chrome files at https://sites.google.com/a/chromium.org/chromedriver/downloads

Once you visit the above link, you will be finding several links to download the required drivers. Check your local system chrome version and download the respective chrome drivers. Once downloaded, the downloaded file will be in ZIP format.  Then unzip the file and save it somewhere in your local system. Then execute the below code, to open the required URL  through the Chrome browser.

package seleniumTutorial;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class ChormeBrowserScript {

public static void main(String [] args) throws InterruptedException{
//System.setProperty(“webdriver.chrome.driver”,path of executable file “Chromedriver.exe”)
System.setProperty(“webdriver.chrome.driver”, “D:/SeleniumEnvironment/chromedriver_win32/chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.get(“https://www.onlineitguru.com”);
System.out.println(“Online IT Certification Training | Online Courses | OnlineITGuru”);
driver.close();
}
}

Get more real time examples on these from selenium online training

Working with Internet Explorer:

Like Firefox and Chrome. this Internet Explorer has separate drivers to test the URLs. You can find the Internet explorer drivers at https://www.seleniumhq.org/download/

Here, you will be finding different links to download the driver. So download the driver according to your local system. And unzip the files and save it somewhere in your local system. Then execute the following code  Eclipse

package rules;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

public class stmtest {

public static void main(String [] args) throws InterruptedException{
//System.setProperty(“webdriver.ie.driver”,path of executable file “IEDriverServer.exe”)
System.setProperty(“webdriver.ie.driver”, “D://Selenium Environment//IEDriverServer_x64_2.53.1//IEDriverServer.exe”);
//Initialize InternetExplorerDriver Instance.
WebDriver driver = new InternetExplorerDriver();
driver.get(“https://www.onlineitguru.com”);
System.out.println(“Online IT Certification Training | Online Courses | OnlineITGuru”);
driver.close();
}
}

 Also Check how to handle Iframes in Selenium Webdriver

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • PEGA Testing Training
  • Today application testing is the deciding factor to launch the application into the market. And people do not launch the application unless it goes true.

  • Blockchain Online Course
  • Today many people were enthusiastic, to know the exact details of things happening around him. This can get the proper knowledge on Blockchain.

  • Ethical Hacking Online Course
  • Zeal to learn ethical hacking is common among college students and IT professionals. Because everybody wants to secure their system from cyber attacks.

  • Python Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • PEGA Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).


100% Secure Payments. All major credit & debit cards accepted.