i
WebDriver Introduction
Selenium WebDriver Architecture
Introduction to WebDriver API
Introduction to WebDriver – Code
Handling Dropdowns and Select class
Handling Multiple Dropdown values and Links
Handling Radio buttons and Checkboxes
Capture Screenshots and Email test results
Browser Navigation Methods
Handling tabs
Capturing screenshot, Handling tabs and pop-ups – Code
Handling tabs and Pop-ups – Code
Handling Alerts
Handling User Authentication and Input alerts
HtmlUnitDriver and Handling Captchas
Handling Web Tables
Synchronization
Handling WebTables, Synchronization issues, Firefoxprofiles – Code
Actions Class
Event Listeners, Event Firing Mouse, Coordinates – Code
Handling Mouse Hover in Selenium
JavascriptExecutor
Handling Iframes
IsElementPresent, IsEnabled, IsSelected
Working with Chrome Driver - Part 1
Working with FireFox Driver - Part 2
Working with Internet Explorer Driver - Part 3
Handling SSL Certificate
Desired Capabilities
How to Encode password in WebDriver
Handling JQuery Elements - Drag and Drop, Sliders, Resizable
Handling JQuery Elements - Drag and Drop, Sliders, Resizable – Code
Working on IE Browser using Actions
TestNG, Ant & Report Generation through XSLT
Introduction to TestNG and Annotations
TestNG Parameterization
Configuring ANT, Generating TestNG & XSLT Reports
Code for generating XSLT / Surefire Reports through MAVEN
TestNG Parameterization Excel Reading
Handling Multiple data providers
TestNG XSLT Jar, Build.xml & TestNG.xml file
Frameworks Introduction
Hybrid (DATA + KEYWORD) driven Framework
Framework Architecture
Reading Excel sheets
TestNG DataProvider
Data Provider with Hashtable
Handling Multiple Test Suites
Multiple DataProviders
Setting up Run-modes at Suite Level
Setting up Runmodes at TestCase Level
Creating a common utility for Run-modes
Hybrid Framework Code
Checking if an element is present or not?
When it comes to validating if the element is present on the web page or not, we need to handle this situation by looking for the element using the findElement() method from WebDriver instance. Once we get the element, then we can for the element value, and if it is not null, then it means the element is present on the web page.
We can see below snippet where we need to check for the presence of "software and it" text on the page.
So, let us see the code to check if the element is present on the web page or not:
package SeleniumTest.SeleniumTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ElementPresent
{
public static void main( String[] args )
{
WebDriver driver=new ChromeDriver();
driver.get("https://selflearning.io/");
WebElement element=driver.findElement(By.xpath("//h2[contains(.,'software and it')]"));
if(element!=null)
{
System.out.println("Element is present on the web page");
}
else
{
System.out.println("Element is not present on the web page");
}
}
}
IsEnabled Method:
Now we face some situation while validation where we need to check whether the element is enabled or not. This can be validated easily by using the WebElement method “IsEnabled". This method takes nothing as a parameter and returns a Boolean value.
We can again take the https://selflearning.io/ web page to validate the “software and it” link text to validate if this is enabled or not.
Let us see the sample code to check the same:
package SeleniumTest.SeleniumTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ElementIsEnabled
{
public static void main( String[] args )
{
WebDriver driver=new ChromeDriver();
driver.get("https://selflearning.io/");
WebElement element=driver.findElement(By.xpath("//h2[contains(.,'software and it')]"));
if(element.isEnabled())
{
System.out.println("Element is enabled on the web page");
}
else
{
System.out.println("Element is not enabled on the web page");
}
}
}
IsSelected Method:
We see situations where we need to check the Checkbox or radio buttons and need to validate if a checkbox or a radio button is already selected or not. This situation can be handled easily by using the "IsSelected” method.
This method takes nothing as a parameter and returns a Boolean value.
package SeleniumTest.SeleniumTest;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ElementIsSelected
{
public static void main( String[] args )
{
WebDriver driver=new ChromeDriver();
driver.get("http://www.echoecho.com/htmlforms10.htm");
List <WebElement> elements=driver.findElements(By.xpath("//table[3]/tbody/tr/td/table/tbody/tr/td/input[@name='group2']"));
int iSize=elements.size();
System.out.println(iSize);
for(int i=0;i<iSize;i++)
{
if(!elements.get(i).isSelected())
{
elements.get(i).click();
}
}
}
}
Don't miss out!