Selenium WebDriver
Benefits of Selenium
Four components of Selenium
Difference b/w Selenium IDE, RC & WebDriver
Selenium WebDriver Architecture
Background when user execute selenium code
Download and Install Java
Download and Install Eclipse
Download Selenium WebDriver
Selenium WebDriver Locators
Selenium - Launch Browser
Selenium WebDriver Waits
Selenium- Implicit wait
Selenium- Explicit wait
Selenium- Fluent wait
Selenium- Commonly used commands
Selenium- findElement & findElements
Selenium- Selenium-Handling check Box
Selenium- Handling Radio button
Selenium- Handling drop down
Selenium- Take Screenshot
Selenium- Handle Web Alerts
Selenium- Multiple Windows Handling
Selenium- Handle iframes
Selenium- Upload a file
Selenium- Download a file
Selenium- Actions Class Utilities
Selenium- Mouse Actions
Selenium- Keyboards Events
Selenium- Handle mouse hover Actions
Selenium- Drag and Drop
Selenium- Scroll a WebPage
Selenium- Context Click / Right Click
Selenium- Double Click
Selenium- Desired Capabilities
Selenium- Assertions
Selenium- Exceptions and Exception Handling
Selenium- Difference b/w driver.close() & driver.quit()
Selenium- difference b/w driver.get() & driver.navigate()
Selenium- JavascriptExecutor
Selenium- Read excel file using Fillo API
Selenium- Database Testing using Selenium
Selenium- Read & write excel file using Apache POI
Selenium- Read and Write csv file in Selenium
Selenium- Dynamic Web Table Handling
Selenium- Maven Integration with Selenium
Selenium- Set up Logging using Log4j
Selenium-Implement Extent Report
Selenium- Commonly used commands
In this section we will learn about a few basic Selenium commands which are frequently used and are very common.
Some of the commonly used commands in Selenium test cases are sendKeys(), click(), IsDisplayed(), refresh(), navigate(),quit(), close(), getTitle(), getCurrentTitle() etc. for performing operations on our web application under test (AUT)
1) Get method
Get Method is used to navigate to a web page by passing a URL as a parameter.
Syntax–
driver.get(“URL”)
2) Navigate method
Navigate Method allows for the browser to move forward(as per browser history) ,Back (as per browser history), Refresh or to open any link.
driver.navigate().to(“URL”);
This command will launch a new web browser window and navigate to the specified URL.
driver.navigate().forward();
This command will navigate to the next web page with reference to the browser’s history.
driver.navigate().back();
This command will take back the user to the previous webpage in the web browser’s history.
driver.navigate().refresh() ;
This command will refresh the current web page there by reloading all the web elements.
3) Refreshing the browser
Below are the methods used to refresh the current web page in the existing browser window.
A browser can be refreshed using multiple methods
a) Using Navigate Method
driver.navigate().refresh();
b) By pressing F5 keyboard button
driver.sendKeys(Keys.F5);
Also there are other methods like driver.get(“URL”) etc.
4) Typing text in text box (Send Keys() Method )
Sendkeys() method in selenium is used to enter values into a text box in Selenium.
Syntax –
driver.sendKeys(“input text”);
We can also enter the value using Java Script executor as well
JavascriptExecutor myExecutor = ((JavascriptExecutor) driver);
myExecutor.executeScript("arguments[0].value='Test';", element);
5) Get Page Title command
getTitle() command in selenium is used to get the current Page title and It returns String value
Syntax –
driver.getTitle();
OR
String title = driver.getTitle()
6) Get Current URL Command
getCurrentUrl() command in selenium is used to get the current URL which is opened in the browser. It will return string value
driver.getCurrentUrl();
OR
String currentURL =driver.getCurrentUrl()
7) Close command
Close command in Selenium is used to close the current browser associated with the driver. This method does not return anything
below is the command-
driver.close() ;
8) quit Command
quit command in selenium is used to quit the driver and closes all the associated windows of that driver.
This method also does not return anything
driver.quit();
9) Click Command
Click() command in selenium is used to perform particular tasks by interacting with links, buttons , check box , radio button and other web elements.
For eg
The below code is used to click on a button element named ‘submit’
Webelement element = driver.findElement(By.id("***Button id ***")); element.click();
10) Get Page Source Command
This method helps in getting the source code of a webPage .This method returns a string value.
String pageSource = driver.getPageSource();
Let us consider a test scenario which will cover most of the basic commands as described above
-
- Open a firefox browser
- Navigate to “https://tutorialshut.com/demo-website-for-selenium-automation-practice/”
- Enter the value in text box
- Click on Submit button
- Get the current Page URL and Print that URL
- Refresh the current Page
- Navigate to Tutorials Hut Home Page using To Command
- Navigate Back to Previous Page using back command
- Close the Browser
package com.test; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class SeleniumBasicCommands { public static WebDriver driver; public static void main(String[] args) { // Create a new instance of the Firefox driver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Launch the URL driver.get("https://tutorialshut.com/demo-website-for-selenium-automation-practice/"); // Enter the value in text box driver.findElement(By.id("fname")).sendKeys("Hi"); // Click on Submit button driver.findElement(By.id("idOfButton")).click(); // Get the current Page URL and Print that URL String currentPageURL = driver.getCurrentUrl(); System.out.println("currentPageURL :" + currentPageURL); // Refresh the current Page driver.navigate().refresh(); Thread.sleep(5000); // Navigate to Tutorials Hut Home Page using To Command driver.navigate().to("https://tutorialshut.com/"); // Navigate Back to Previous Page using back command driver.navigate().back(); driver.close(); } }
Selenium WebDriver Tutorials
Benefits of Selenium
Four components of Selenium
Difference b/w Selenium IDE, RC & WebDriver
Selenium WebDriver Architecture
Background when user execute selenium code
Download and Install Java
Download and Install Eclipse
Download Selenium WebDriver
Selenium WebDriver Locators
Selenium - Launch Browser
Selenium WebDriver Waits
Selenium- Implicit wait
Selenium- Explicit wait
Selenium- Fluent wait
Selenium- Commonly used commands
Selenium- findElement & findElements
Selenium- Selenium-Handling check Box
Selenium- Handling Radio button
Selenium- Handling drop down
Selenium- Take Screenshot
Selenium- Handle Web Alerts
Selenium- Multiple Windows Handling
Selenium- Handle iframes
Selenium- Upload a file
Selenium- Download a file
Selenium- Actions Class Utilities
Selenium- Mouse Actions
Selenium- Keyboards Events
Selenium- Handle mouse hover Actions
Selenium- Drag and Drop
Selenium- Scroll a WebPage
Selenium- Context Click / Right Click
Selenium- Double Click
Selenium- Desired Capabilities
Selenium- Assertions
Selenium- Exceptions and Exception Handling
Selenium- Difference b/w driver.close() & driver.quit()
Selenium- difference b/w driver.get() & driver.navigate()
Selenium- JavascriptExecutor
Selenium- Read excel file using Fillo API
Selenium- Database Testing using Selenium
Selenium- Read & write excel file using Apache POI
Selenium- Read and Write csv file in Selenium
Selenium- Dynamic Web Table Handling
Selenium- Maven Integration with Selenium
Selenium- Set up Logging using Log4j
Selenium-Implement Extent Report