Complete Selenium Tutorial for beginner to Expert in 2020

Complete Selenium Tutorial for beginner | In this article, we are going to learn Selenium Basic Programs

Selenium in 2020

 

1. Program to open browser and website using selenium

 

package automationHRM;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstProgram {

public void runBrowser () {
System.setProperty("webdriver.gecko.driver", "D:\SeleniumLib\geckodriver.exe"); // set path of geckodriver
WebDriver driver = new FirefoxDriver(); // create object of FirefoxDriver

driver.get("https://atf.mydynamicerp.com/"); // hit the url on browser

driver.manage().window().maximize(); // maximize the window

}

public static void main(String[] args) {
//which browser you want to use
// open the browser
// hit the URL of any browser.

FirstProgram run = new FirstProgram();
run.runBrowser();

}

}

 

2. Program to Maximize and minimize browser using Selenium

 

package automationHRM;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MaximizeMinimizeBrowser {

public void maximizwMinimize() {
System.setProperty("webdriver.gecko.driver", "D:\SeleniumLib\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.minetechtips.com");
driver.manage().window().maximize(); //For minimizing Browser
driver.manage().window().maximize(); //For maximizing browser in full scree

}

public static void main(String[] args) {
MaximizeMinimizeBrowser maxMinBrowser = new MaximizeMinimizeBrowser();
maxMinBrowser.maximizwMinimize();

}
}

 

 

3. Program to click on the backward and forward button of browser using Selenium

 

package automationHRM;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BrowserForwardBackwardButton {

public void backwardForwardButton() throws InterruptedException {

System.setProperty("webdriver.gecko.driver", "D:\SeleniumLib\geckodriver.exe");

WebDriver driver = new FirefoxDriver();
driver.get("https://www.minetechtips.com/");
Thread.sleep(5000);
driver.get("https://www.minetechtips.com/2019/12/20-popular-social-media-sites.html");
driver.navigate().back(); //to click on Backward button
driver.navigate().forward(); // to click on forward button
}

public static void main(String[] args) throws InterruptedException {

BrowserForwardBackwardButton forwardBackward = new BrowserForwardBackwardButton();
forwardBackward.backwardForwardButton();

}

}

 

 

4. Program to navigate or to find element by linktext using Selenium

package automationHRM;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class NavigationElement {

public void runBrowser() {
System.setProperty("webdriver.gecko.driver", "D:\SeleniumLib\geckodriver.exe");   // set path of geckodriver
WebDriver driver = new FirefoxDriver();  // create object of FirefoxDriver
driver.get("https://www.minetechtips.com/");
String getTextofElement = driver.findElement(By.linkText("Blogging")).getText();
System.out.println(getTextofElement);

}

public static void main(String[] args) {

NavigationElement findElementName = new NavigationElement();
findElementName.runBrowser();
}

}

 

 

5. Customized XPath and CSS selector on Selenium

package automationHRM;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CustomizeXpathCSSselectors {

/* Creating Custom xPath if there is no ID or Class available of CSS elements.
* <input name="email" placeholder="Email address..." type="text">
*
*
* //input[@placeholder='Email address...']   Double slash must be used
*/
void customizeXpathAndCSS() {
System.setProperty("webdriver.gecko.driver", "D:\SeleniumLib\geckodriver.exe");  //Setting Driver location
WebDriver driver = new FirefoxDriver(); //Creating object of webdriver
driver.get("https://www.minetechtips.com");  //Target link
driver.findElement(By.xpath("//input[@placeholder='Email address...']")).clear();  //Setting Xpath and clearing default input value
driver.findElement(By.xpath("//input[@placeholder='Email address...']")).sendKeys("[email protected]"); //Calling Xpath and replaced input field with new value.
driver.findElement(By.cssSelector("[placeholder = 'Email address...']")); //CSS Selector.

}

public static void main(String[] args) {

CustomizeXpathCSSselectors customizeXpathCSSselectors = new CustomizeXpathCSSselectors();
customizeXpathCSSselectors.customizeXpathAndCSS();
}

}


 

Heading

CODE HERE

 

Heading

CODE HERE

 

Heading

CODE HERE

 

Heading

CODE HERE