<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jessica Schuller</title>
    <description>The latest articles on DEV Community by Jessica Schuller (@jessicaschuller).</description>
    <link>https://dev.to/jessicaschuller</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F112801%2F6ee0288e-1913-41a4-b1e1-38e5337eca3b.jpg</url>
      <title>DEV Community: Jessica Schuller</title>
      <link>https://dev.to/jessicaschuller</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jessicaschuller"/>
    <language>en</language>
    <item>
      <title>Write the First Script in Selenium Webdriver: Java code example</title>
      <dc:creator>Jessica Schuller</dc:creator>
      <pubDate>Wed, 28 Nov 2018 08:42:04 +0000</pubDate>
      <link>https://dev.to/jessicaschuller/write-the-first-script-in-selenium-webdriver-java-code-example-4nal</link>
      <guid>https://dev.to/jessicaschuller/write-the-first-script-in-selenium-webdriver-java-code-example-4nal</guid>
      <description>&lt;p&gt;In this blog, you will be given an opportunity to get used to Selenium automation testing as well as the complete instructions of &lt;strong&gt;how to write a script in Selenium WebDriver&lt;/strong&gt; as a basic level. The tutorial also provides you an actual Java code as a &lt;strong&gt;Selenium WebDriver example&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;Audience&lt;/h2&gt;

&lt;p&gt;The tutorial provides automation testers the basic knowledge of &lt;strong&gt;how to write the script in Selenium Webdriver&lt;/strong&gt; and practical examples. The article contains enough ingredients to let you start with Selenium WebDriver from where you can independently take yourself to higher levels of expertise.&lt;/p&gt;

&lt;h2&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;Before starting with this tutorial, you need to have a basic knowledge of Java or any other object-oriented coding language. Moreover, you should be proficient in the basic principles of testing concepts, especially the concept of &lt;strong&gt;Selenium Automation Testing&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;Getting started with Selenium WebDriver Scripting&lt;/h2&gt;

&lt;p&gt;Assume that you want to &lt;strong&gt;write the script in Selenium Webdriver&lt;/strong&gt; that could:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Fetch Fox News’ homepage&lt;/li&gt;
    &lt;li&gt;Verify its title&lt;/li&gt;
    &lt;li&gt;Print out the result of the comparison&lt;/li&gt;
    &lt;li&gt;Close it before ending the entire program&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;WebDriver code&lt;/h2&gt;

&lt;p&gt;Below is the &lt;a href="https://seleniumtestingtutorials.com/selenium-webdriver/write-script-selenium-webdriver-java//" rel="noopener noreferrer"&gt;&lt;strong&gt;Selenium WebDriver example&lt;/strong&gt;&lt;/a&gt; for the logic presented by the scenario mentioned above.&lt;/p&gt;

&lt;p&gt;Note: Gecko driver generated by Mozilla should be taken into account when using WebDriver. Selenium 3.0, Firefox and gecko have compatibility issues and setting them appropriately could become a difficult task. If the code cannot be activated, the lower version of Firefox should be downloaded. Otherwise, you can run your Selenium script on Chrome. You only need to change 3 lines of the code to let your script work with Firefox or Chrome.&lt;/p&gt;

&lt;pre&gt;package newproject;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

//comment the above line and uncomment below line to use Chrome

//import org.openqa.selenium.chrome.ChromeDriver;

public class PG1 {

public static void main(String[] args) {

// declaration and instantiation of objects/variables

System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");

WebDriver driver = new FirefoxDriver();

//comment the above 2 lines and uncomment below 2 lines to use Chrome

//System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");

//WebDriver driver = new ChromeDriver();

String baseUrl = "http://www.foxnews.com/";

String expectedTitle = "Fox News - Breaking News Updates | Latest News Headlines | Photos &amp;amp; News Videos";

String actualTitle = "";

// launch Fire fox and direct it to the Base URL

driver.get(baseUrl);

// get the actual value of the title

actualTitle = driver.getTitle();

/*

* compare the actual title of the page with the expected one and print

* the result as "Passed" or "Failed"

*/

if (actualTitle.contentEquals(expectedTitle)){

System.out.println("Test Passed!");

} else {

System.out.println("Test Failed");

}

//close Fire fox

driver.close();

}

}&lt;/pre&gt;

&lt;h2&gt;Explanation of the code&lt;/h2&gt;

&lt;h3&gt;Importing Packages/Statements&lt;/h3&gt;

&lt;p&gt;First of all, you need to import the following two packages to be ready:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;
&lt;strong&gt;org.openqa.selenium.*: &lt;/strong&gt;references the WebDriver interface required to instantiate a new web browser.&lt;/li&gt;
    &lt;li&gt;
&lt;strong&gt;org.openqa.selenium.firefox.FirefoxDriver&lt;/strong&gt;: references the FirefoxDriver class required to instantiate a Firefox-specific driver on the browser operated by the WebDriver class.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your test requires more complex tasks such as capturing browser screens, accessing another class or manipulating external files, you definitely will need to import more packages.&lt;/p&gt;

&lt;h3&gt;Instantiating objects and variables&lt;/h3&gt;

&lt;p&gt;Generally, this is how a driver object is instantiated:&lt;/p&gt;

&lt;pre&gt;WebDriver driver - new FirefoxDriver();&lt;/pre&gt;

&lt;p&gt;The Base URL and the expected title are saved as variables.&lt;/p&gt;

&lt;h3&gt;Launching a Browser Session&lt;/h3&gt;

&lt;p&gt;WebDriver &lt;strong&gt;get() &lt;/strong&gt;method helps launch a new browser session and deliver it directly to the URL that you specify as its parameter.&lt;/p&gt;

&lt;pre&gt;driver.get(baseUrl);&lt;/pre&gt;

&lt;h3&gt;Getting the actual page title&lt;/h3&gt;

&lt;p&gt;You can verify the page title of the currently loading page by using the &lt;strong&gt;getTitle()&lt;/strong&gt; method of the WebDriver interface.&lt;/p&gt;

&lt;pre&gt;actualTitle = driver.getTitle();&lt;/pre&gt;

&lt;h3&gt;Comparing the Actual and Expected Values&lt;/h3&gt;

&lt;p&gt;This part of the code simply applies a basic Java if-else format to make a comparison between the actual and expected title.&lt;/p&gt;

&lt;pre&gt; if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");

} else {

System.out.println("Test Failed");

}&lt;/pre&gt;

&lt;h3&gt;Ending a browser session&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;close()&lt;/strong&gt; method helps you to close the browser window.&lt;/p&gt;

&lt;pre&gt;  driver.close();&lt;/pre&gt;

&lt;h3&gt;Ending the entire program&lt;/h3&gt;

&lt;p&gt;In case you use this command without closing all browser windows first, your entire Java program will be ended while the browser window is still opening.&lt;/p&gt;

&lt;pre&gt;system.exist(0)&lt;/pre&gt;

&lt;h2&gt;Executing the test&lt;/h2&gt;

&lt;p&gt;There are two ways to run the code in Eclipse.&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;On Eclipse menu bar, choose &lt;strong&gt;Run&lt;/strong&gt; &amp;gt; &lt;strong&gt;Run&lt;/strong&gt;.&lt;/li&gt;
    &lt;li&gt;Press &lt;strong&gt;Ctrl+F11&lt;/strong&gt; to run the entire code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-1-1.png" alt="Run on Eclipse Menu Bar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you completed everything correctly, Eclipse would output “Test Passed!”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-2-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-2-1.png" alt="Test Passed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Locating Web Elements&lt;/h2&gt;

&lt;p&gt;We use the Dynamic finders &lt;strong&gt;findElement(By.locator())&lt;/strong&gt; to locate elements in WebDriver.&lt;/p&gt;

&lt;p&gt;Following is an example code which locates an element by its id. Let’s take Facebook as an example of the Base URL.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre&gt;package newproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class PG2 {

   public static void main(String[] args) {

    System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");

    WebDriver driver = new FirefoxDriver();

       String baseUrl = "http://www.facebook.com";

       String tagName = "";

       

       driver.get(baseUrl);

       tagName = driver.findElement(By.id("email")).getTagName();

       System.out.println(tagName);

       driver.close();

       System.exit(0);

}

}&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We can use the &lt;strong&gt;getTagName() &lt;/strong&gt;method to extract the tag name of the particular element whose id named “email”. When being executed, this code should have the ability to identify exactly the tag name “input” and will extract to Eclipse Console window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-3-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-3-1.png" alt="Console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Locator Types and their Syntax&lt;/h2&gt;

&lt;p&gt;Locate by value of the “id” attributeLocate by value of the “class” attributeLocate by value of thetext of the hyperlinkLocate by value of thesub-text of the hyperlinkLocate by value of the“name” attributeLocate by value of the xpathLocate by value ofthe CSS selector&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;Locator Type&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;Syntax&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;id&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.id(“ID_of_Element”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of &lt;/span&gt;

&lt;span&gt;the “id” attribute&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;className&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.className&lt;/span&gt;

&lt;span&gt;(“Class_of_Element”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of &lt;/span&gt;

&lt;span&gt;the “class” attribute&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;linkText&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.linkText(“Text”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of the&lt;/span&gt;

&lt;span&gt;text of the hyperlink&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;partialLinkText&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.partialLinkText&lt;/span&gt;

&lt;span&gt;(“PartialText”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of the&lt;/span&gt;

&lt;span&gt;sub-text of the hyperlink&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;name&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.name&lt;/span&gt;

&lt;span&gt;(“Name_of_Element”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of the&lt;/span&gt;

&lt;span&gt;“name” attribute&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;xpath&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.xpath(“Xpath”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value &lt;/span&gt;

&lt;span&gt;of the xpath&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;cssSelector&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.cssSelector&lt;/span&gt;

&lt;span&gt;(“CSS Selector”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of&lt;/span&gt;

&lt;span&gt;the CSS selector&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;tagName&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;driver.findElement&lt;/span&gt;

&lt;span&gt;(By.tagName(“input”))&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span&gt;Locate by value of&lt;/span&gt;

&lt;span&gt;its tag name&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;This tutorial provided you the instructions of &lt;a href="https://seleniumtestingtutorials.com/selenium-webdriver/write-script-selenium-webdriver-java/" rel="noopener noreferrer"&gt;&lt;strong&gt;how to write script in Selenium WebDriver &lt;/strong&gt;&lt;/a&gt; in a basic level. The blog also discussed the different elements that constitute a Selenium WebDriver script.&lt;/p&gt;

&lt;p&gt;Below is the summary of this Selenium WebDriver tutorial:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Before scripting, you need to import the packages which allow you to create a WebDriver script.&lt;/li&gt;
    &lt;li&gt;The &lt;strong&gt;get()&lt;/strong&gt; method helps launch a pure web browser instance.&lt;/li&gt;
    &lt;li&gt;The &lt;strong&gt;getTitle()&lt;/strong&gt; method retrieves the page title and assigns the retrieved title to a String object.&lt;/li&gt;
    &lt;li&gt;In WebDriver, we can locate web elements using Dynamic finders.&lt;/li&gt;
    &lt;li&gt;The following are the available locator types:
&lt;ul&gt;
    &lt;li&gt;Id&lt;/li&gt;
    &lt;li&gt;className&lt;/li&gt;
    &lt;li&gt;name&lt;/li&gt;
    &lt;li&gt;XPath&lt;/li&gt;
    &lt;li&gt;cssSelector&lt;/li&gt;
    &lt;li&gt;linkText&lt;/li&gt;
    &lt;li&gt;partialLinkText&lt;/li&gt;
    &lt;li&gt;tagName&lt;/li&gt;
&lt;/ul&gt;




&lt;/li&gt;


&lt;/ul&gt;

</description>
      <category>seleniumtutorials</category>
      <category>seleniumwebdriver</category>
    </item>
    <item>
      <title>Write the First Script in Selenium Webdriver: Java code example</title>
      <dc:creator>Jessica Schuller</dc:creator>
      <pubDate>Wed, 28 Nov 2018 08:39:32 +0000</pubDate>
      <link>https://dev.to/jessicaschuller/write-the-first-script-in-selenium-webdriver-java-code-example-1gp2</link>
      <guid>https://dev.to/jessicaschuller/write-the-first-script-in-selenium-webdriver-java-code-example-1gp2</guid>
      <description>&lt;p&gt;In this blog, you will be given an opportunity to get used to Selenium automation testing as well as the complete instructions of &lt;strong&gt;how to write a script in Selenium WebDriver&lt;/strong&gt; as a basic level. The tutorial also provides you an actual Java code as a &lt;strong&gt;Selenium WebDriver example&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;Audience&lt;/h2&gt;

&lt;p&gt;The tutorial provides automation testers the basic knowledge of &lt;strong&gt;how to write the script in Selenium Webdriver&lt;/strong&gt; and practical examples. The article contains enough ingredients to let you start with Selenium WebDriver from where you can independently take yourself to higher levels of expertise.&lt;/p&gt;

&lt;h2&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;Before starting with this tutorial, you need to have a basic knowledge of Java or any other object-oriented coding language. Moreover, you should be proficient in the basic principles of testing concepts, especially the concept of &lt;strong&gt;Selenium Automation Testing&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;Getting started with Selenium WebDriver Scripting&lt;/h2&gt;

&lt;p&gt;Assume that you want to &lt;strong&gt;write the script in Selenium Webdriver&lt;/strong&gt; that could:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Fetch Fox News’ homepage&lt;/li&gt;
    &lt;li&gt;Verify its title&lt;/li&gt;
    &lt;li&gt;Print out the result of the comparison&lt;/li&gt;
    &lt;li&gt;Close it before ending the entire program&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;WebDriver code&lt;/h2&gt;

&lt;p&gt;Below is the &lt;a href="https://seleniumtestingtutorials.com/selenium-webdriver/write-script-sel%E2%80%A6m-webdriver-java/" rel="noopener noreferrer"&gt;&lt;strong&gt;Selenium WebDriver example&lt;/strong&gt;&lt;/a&gt; for the logic presented by the scenario mentioned above.&lt;/p&gt;

&lt;p&gt;Note: Gecko driver generated by Mozilla should be taken into account when using WebDriver. Selenium 3.0, Firefox and gecko have compatibility issues and setting them appropriately could become a difficult task. If the code cannot be activated, the lower version of Firefox should be downloaded. Otherwise, you can run your Selenium script on Chrome. You only need to change 3 lines of the code to let your script work with Firefox or Chrome.&lt;/p&gt;

&lt;pre&gt;package newproject;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

//comment the above line and uncomment below line to use Chrome

//import org.openqa.selenium.chrome.ChromeDriver;

public class PG1 {

public static void main(String[] args) {

// declaration and instantiation of objects/variables

System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");

WebDriver driver = new FirefoxDriver();

//comment the above 2 lines and uncomment below 2 lines to use Chrome

//System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");

//WebDriver driver = new ChromeDriver();

String baseUrl = "http://www.foxnews.com/";

String expectedTitle = "Fox News - Breaking News Updates | Latest News Headlines | Photos &amp;amp; News Videos";

String actualTitle = "";

// launch Fire fox and direct it to the Base URL

driver.get(baseUrl);

// get the actual value of the title

actualTitle = driver.getTitle();

/*

* compare the actual title of the page with the expected one and print

* the result as "Passed" or "Failed"

*/

if (actualTitle.contentEquals(expectedTitle)){

System.out.println("Test Passed!");

} else {

System.out.println("Test Failed");

}

//close Fire fox

driver.close();

}

}&lt;/pre&gt;

&lt;h2&gt;Explanation of the code&lt;/h2&gt;

&lt;h3&gt;Importing Packages/Statements&lt;/h3&gt;

&lt;p&gt;First of all, you need to import the following two packages to be ready:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;
&lt;strong&gt;org.openqa.selenium.*: &lt;/strong&gt;references the WebDriver interface required to instantiate a new web browser.&lt;/li&gt;
    &lt;li&gt;
&lt;strong&gt;org.openqa.selenium.firefox.FirefoxDriver&lt;/strong&gt;: references the FirefoxDriver class required to instantiate a Firefox-specific driver on the browser operated by the WebDriver class.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your test requires more complex tasks such as capturing browser screens, accessing another class or manipulating external files, you definitely will need to import more packages.&lt;/p&gt;

&lt;h3&gt;Instantiating objects and variables&lt;/h3&gt;

&lt;p&gt;Generally, this is how a driver object is instantiated:&lt;/p&gt;

&lt;pre&gt;WebDriver driver - new FirefoxDriver();&lt;/pre&gt;

&lt;p&gt;The Base URL and the expected title are saved as variables.&lt;/p&gt;

&lt;h3&gt;Launching a Browser Session&lt;/h3&gt;

&lt;p&gt;WebDriver &lt;strong&gt;get() &lt;/strong&gt;method helps launch a new browser session and deliver it directly to the URL that you specify as its parameter.&lt;/p&gt;

&lt;pre&gt;driver.get(baseUrl);&lt;/pre&gt;

&lt;h3&gt;Getting the actual page title&lt;/h3&gt;

&lt;p&gt;You can verify the page title of the currently loading page by using the &lt;strong&gt;getTitle()&lt;/strong&gt; method of the WebDriver interface.&lt;/p&gt;

&lt;pre&gt;actualTitle = driver.getTitle();&lt;/pre&gt;

&lt;h3&gt;Comparing the Actual and Expected Values&lt;/h3&gt;

&lt;p&gt;This part of the code simply applies a basic Java if-else format to make a comparison between the actual and expected title.&lt;/p&gt;

&lt;pre&gt; if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");

} else {

System.out.println("Test Failed");

}&lt;/pre&gt;

&lt;h3&gt;Ending a browser session&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;close()&lt;/strong&gt; method helps you to close the browser window.&lt;/p&gt;

&lt;pre&gt;  driver.close();&lt;/pre&gt;

&lt;h3&gt;Ending the entire program&lt;/h3&gt;

&lt;p&gt;In case you use this command without closing all browser windows first, your entire Java program will be ended while the browser window is still opening.&lt;/p&gt;

&lt;pre&gt;system.exist(0)&lt;/pre&gt;

&lt;h2&gt;Executing the test&lt;/h2&gt;

&lt;p&gt;There are two ways to run the code in Eclipse.&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;On Eclipse menu bar, choose &lt;strong&gt;Run&lt;/strong&gt; &amp;gt; &lt;strong&gt;Run&lt;/strong&gt;.&lt;/li&gt;
    &lt;li&gt;Press &lt;strong&gt;Ctrl+F11&lt;/strong&gt; to run the entire code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-1-1.png" alt="Run on Eclipse Menu Bar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you completed everything correctly, Eclipse would output “Test Passed!”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-2-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-2-1.png" alt="Test Passed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Locating Web Elements&lt;/h2&gt;

&lt;p&gt;We use the Dynamic finders &lt;strong&gt;findElement(By.locator())&lt;/strong&gt; to locate elements in WebDriver.&lt;/p&gt;

&lt;p&gt;Following is an example code which locates an element by its id. Let’s take Facebook as an example of the Base URL.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre&gt;package newproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class PG2 {

   public static void main(String[] args) {

    System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");

    WebDriver driver = new FirefoxDriver();

       String baseUrl = "http://www.facebook.com";

       String tagName = "";

       

       driver.get(baseUrl);

       tagName = driver.findElement(By.id("email")).getTagName();

       System.out.println(tagName);

       driver.close();

       System.exit(0);

}

}&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We can use the &lt;strong&gt;getTagName() &lt;/strong&gt;method to extract the tag name of the particular element whose id named “email”. When being executed, this code should have the ability to identify exactly the tag name “input” and will extract to Eclipse Console window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-3-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fseleniumtestingtutorials.com%2Fwp-content%2Fuploads%2F2018%2F10%2FSelenium-WebDriver-3-1.png" alt="Console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Locator Types and their Syntax&lt;/h2&gt;

&lt;p&gt;Locate by value of the “id” attributeLocate by value of the “class” attributeLocate by value of thetext of the hyperlinkLocate by value of thesub-text of the hyperlinkLocate by value of the“name” attributeLocate by value of the xpathLocate by value ofthe CSS selector&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Locator Type&lt;/td&gt;
&lt;td&gt;Syntax&lt;/td&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;id&lt;/td&gt;
&lt;td&gt;driver.findElement(By.id(“ID_of_Element”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;className&lt;/td&gt;
&lt;td&gt;driver.findElement(By.className(“Class_of_Element”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;linkText&lt;/td&gt;
&lt;td&gt;driver.findElement(By.linkText(“Text”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;partialLinkText&lt;/td&gt;
&lt;td&gt;driver.findElement(By.partialLinkText(“PartialText”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;name&lt;/td&gt;
&lt;td&gt;driver.findElement(By.name(“Name_of_Element”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;xpath&lt;/td&gt;
&lt;td&gt;driver.findElement(By.xpath(“Xpath”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;cssSelector&lt;/td&gt;
&lt;td&gt;driver.findElement(By.cssSelector(“CSS Selector”))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tagName&lt;/td&gt;
&lt;td&gt;driver.findElement(By.tagName(“input”))&lt;/td&gt;
&lt;td&gt;Locate by value ofits tag name&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;This tutorial provided you the instructions of &lt;a href="https://seleniumtestingtutorials.com/selenium-webdriver/write-script-sel%E2%80%A6m-webdriver-java/" rel="noopener noreferrer"&gt;&lt;strong&gt;how to write script in Selenium WebDriver &lt;/strong&gt;&lt;/a&gt; in a basic level. The blog also discussed the different elements that constitute a Selenium WebDriver script.&lt;/p&gt;

&lt;p&gt;Below is the summary of this Selenium WebDriver tutorial:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Before scripting, you need to import the packages which allow you to create a WebDriver script.&lt;/li&gt;
    &lt;li&gt;The &lt;strong&gt;get()&lt;/strong&gt; method helps launch a pure web browser instance.&lt;/li&gt;
    &lt;li&gt;The &lt;strong&gt;getTitle()&lt;/strong&gt; method retrieves the page title and assigns the retrieved title to a String object.&lt;/li&gt;
    &lt;li&gt;In WebDriver, we can locate web elements using Dynamic finders.&lt;/li&gt;
    &lt;li&gt;The following are the available locator types:
&lt;ul&gt;
    &lt;li&gt;Id&lt;/li&gt;
    &lt;li&gt;className&lt;/li&gt;
    &lt;li&gt;name&lt;/li&gt;
    &lt;li&gt;XPath&lt;/li&gt;
    &lt;li&gt;cssSelector&lt;/li&gt;
    &lt;li&gt;linkText&lt;/li&gt;
    &lt;li&gt;partialLinkText&lt;/li&gt;
    &lt;li&gt;tagName&lt;/li&gt;
&lt;/ul&gt;




&lt;/li&gt;


&lt;/ul&gt;

</description>
      <category>seleniumtutorials</category>
      <category>seleniumwebdriver</category>
    </item>
    <item>
      <title>Introduction to Selenium Automation Testing</title>
      <dc:creator>Jessica Schuller</dc:creator>
      <pubDate>Wed, 07 Nov 2018 04:26:05 +0000</pubDate>
      <link>https://dev.to/jessicaschuller/introduction-to-selenium-automation-testing-2eha</link>
      <guid>https://dev.to/jessicaschuller/introduction-to-selenium-automation-testing-2eha</guid>
      <description>&lt;p&gt;In an era of extremely interactive and responsive software processes where several enterprises are using some form of Agile methodology, automation testing has become crucial for many software projects. Automation testing beats manual one all the time as it requires less time and human resource has a lower risk for errors, allows regular execution, supports lights out the execution, regression testing and also functional testing. There are many commercial and open source tools available for supporting the growth of automation testing. Specifically, Selenium is one of the most widely-used tools to build test automation for web applications.&lt;/p&gt;

&lt;h2&gt;1. What is Selenium Testing?&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a-I5xRvN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Cross-browser-testing-in-Selenium-Webdriver-2.png" class="article-body-image-wrapper"&gt;&lt;img class="aligncenter wp-image-357 size-full" src="https://res.cloudinary.com/practicaldev/image/fetch/s--a-I5xRvN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Cross-browser-testing-in-Selenium-Webdriver-2.png" alt="Selenium introduction" width="525" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selenium first came in 2004 when Jason Huggins was testing an internal application at ThoughtWorks. Having realized the repetitious manual testing of their applications became ineffective, he created a Javascript which could drive interactions with the page, allowing him to automatically rerun tests against various browsers. Selenium was an outstanding innovation at that time because no other product allowed users to control a browser from a language of their choice.&lt;/p&gt;

&lt;p&gt;In general, Selenium is an open source framework that allows users to test applications across various browsers and platforms. It offers a number of tools and APIs for automating user interaction on pure HTML and JavaScript applications in browsers such as Firefox, IE, Google Chrome, Safari, and so on. What makes Selenium highly flexible is the ability to bind to different common languages, allowing users to write in their preferred programming languages such as Java, Javascript, C#, PHP, Perl, Ruby, .Net, and Python.&lt;/p&gt;

&lt;h2&gt;2. Why is Selenium getting popular?&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3s9g0afk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Test-Automation.jpg" class="article-body-image-wrapper"&gt;&lt;img class="size-full wp-image-360 aligncenter" src="https://res.cloudinary.com/practicaldev/image/fetch/s--3s9g0afk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Test-Automation.jpg" alt="Test Automation" width="960" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Current technology is completely dominated by machines whose behavior is controlled by software. Will the machines behave as we want them to? Everywhere? Every time? Software testing is key to getting the answers we need for these questions. At the end of the day, it is the software application’s success rate which is going to control your business development. This is also true for web applications because the internet is currently the town square of the global village and websites have become the billboards to advertise businesses.&lt;/p&gt;

&lt;p&gt;Let’s take the e-commerce industry as an example. Be it Amazon, Flipkart or eBay, online companies rely on customer traffic to their websites and web-based mobile applications for business. Imagine if something catastrophic happened such as the prices of a number of products being capped off at $10, all because of a small bug in a “not so easily readable” part of the code. How can we prevent such a disaster? By testing the code before deployment, right? This takes us to the next topic of manual testing.&lt;/p&gt;

&lt;p&gt;Manual testing refers to QA testers manually resting web application. Tests need to be performed manually in every environment, using various datasets while recording the success or failure rate of every transaction. The challenges of relying on human testers include fatigue, boredom, delay in work, mistakes and errors due to manual work. These flaws indicate the need for automation testing as well as the importance of Selenium.&lt;/p&gt;

&lt;h2&gt;3. Breaking down the Selenium suite&lt;/h2&gt;

&lt;h3&gt;3.1. The Beginning - Selenium IDE&lt;/h3&gt;

&lt;p&gt;Selenium Integrated Development Environment (IDE) is the Firefox plug-in tool that allows users to record, playback, edit and debug test scripts to export them in a preferred programming language. Thanks to specific language IDE provided to a test domain, users can use the tool to test without learning a new scripting language and makes it much easier and more convenient to send commands to the browser and automate testing. However, users can only use the tool, which is limited, to test web applications in Firefox, and thus other browsers cannot be tested by using IDE.&lt;/p&gt;

&lt;h3&gt;3.2. The Evolution - Selenium RC and Webdriver&lt;/h3&gt;

&lt;p&gt;Selenium Remote Control (RC), or Selenium 1, can help users run the test script in various browsers by launching them as a proxy server. However, with the introduction of the extended version - &lt;a href="https://seleniumtestingtutorials.com/selenium-tutorials/write-script-selenium-webdriver-java/" rel="noopener"&gt;Webdriver (Selenium 2)&lt;/a&gt;, RC is no longer supported.&lt;/p&gt;

&lt;p&gt;Webdriver is widely-used among developers and QA teams for regressions tests and cross-browser testing, as it allows users to test on a spectrum of browsers and operating systems using the native operating system functionality. This means that commands perform as a human would if they were using the same browser.&lt;/p&gt;

&lt;h3&gt;3.3. Optimization - Selenium Grid&lt;/h3&gt;

&lt;p&gt;Selenium Grid lets users run multiple tests simultaneously on various browsers and machines to speed up testing. Selenium Grid contains one machine called a hub and multiple nodes for execution. The more nodes users have, the more tests they can run at the same time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uCkmIoSx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Globel-networking-Converted-1024x662-1.png" class="article-body-image-wrapper"&gt;&lt;img class="size-full wp-image-361 aligncenter" src="https://res.cloudinary.com/practicaldev/image/fetch/s--uCkmIoSx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Globel-networking-Converted-1024x662-1.png" alt="Selenium IDE" width="1024" height="662"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;4. The future of Selenium&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7HyuvNQo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Components-of-Selenium-e1539747834705-1.png" class="article-body-image-wrapper"&gt;&lt;img class="size-full wp-image-362 aligncenter" src="https://res.cloudinary.com/practicaldev/image/fetch/s--7HyuvNQo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/Components-of-Selenium-e1539747834705-1.png" alt="Selenium components" width="808" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Global enterprises are increasingly shifting towards the adoption of Selenium because of attractive benefits provided by the automation testing tool - cost-effectiveness, high speed, compatibility, and much more. This means the need for Selenium will grow enormously in the near future. As a result, Selenium 4 is all set to release at the end of 2018. Major improvements in the upcoming Selenium version 4 have been revealed, including a new protocol, new plugin system and CLI runner, improved Selenium Grid and so on.&lt;/p&gt;

&lt;p&gt;Besides, Selenium-based automation tools are being more popular. For instance, Winium is a Selenium-based tool for testing and automating desktop applications on the Windows desktop. It is easy to adapt for those who are familiar with and already aware of most of the functionality on Selenium. There are currently a few bugs in Winium and it is still undergoing a development process, just like Selenium once did.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BD1C6z7h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/5-best-practices-of-implementing-selenium-test-automation-1.jpg" class="article-body-image-wrapper"&gt;&lt;img class="aligncenter wp-image-363 size-full" src="https://res.cloudinary.com/practicaldev/image/fetch/s--BD1C6z7h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seleniumtestingtutorials.com/wp-content/uploads/2018/10/5-best-practices-of-implementing-selenium-test-automation-1.jpg" alt="Future Selenium" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Furthermore, while Selenium is the most popular method of QA testing, it demands programming skills, knowledge, time and effort to create the test automation framework to meet specific testing requirements. Therefore, there has been an increasing demand for an alternative approach that eliminates Selenium's technical complexities to allow testers to efficiently set up, create, run, report and manage their automated tests. Katalon Studio (Free tool), UFT (Commercial tool), TestComplete (Commercial tool) seem like the worthy contenders in this department.&lt;/p&gt;

&lt;p&gt;So that draws the conclusion to this blog on &lt;a href="https://seleniumtestingtutorials.com/selenium-basics/selenium-introduction/"&gt;what is Selenium Testing&lt;/a&gt;. In the world of software testing, Selenium has become an omnipresent name. As the automation testing continues to grow, Selenium, along with its alternatives, will pick up their inspiration and keep going on with great successors for the mission of helping automation testing become better everyday.&lt;/p&gt;

</description>
      <category>seleniumtesting</category>
      <category>automationtesting</category>
      <category>seleniumtutorials</category>
      <category>seleniumbeginners</category>
    </item>
  </channel>
</rss>
