How to verify single checkbox in a webpage using selenium?

TestSteps

  • Open the Firefox browser
  • Navigate the AppUrl
  • Identify Checkbox1
  • Select Checkbox1
  • Verify Checkbox1
  • Close the current Browser window

Selenium Code :

——————–

package seleniumProject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

 

public class VerifyCheckbox {

public static void main(String[] args) {

  //open the firefox browser

WebDriver Driver = new FirefoxDriver();

  //navigate the AppUrl

Driver.get(“http://demo.guru99.com/test/radio.html”);

// Identify Checkbox1

WebElement CheckBox1= Driver.findElement(By.id(“vfb-6-0”));

//Select Checkbox1

CheckBox1.click();

   //Verify Checkbox1

if (CheckBox1.isSelected())

{

System.out.println(“Checkbox1 Selected”);

} else

{

System.out.println(“Checkbox1 not Selected”);

}

  //Close the current Browser window

Driver.close();

}

}

How to verify multiple checkboxes in a webpage using sselenium?

TestSteps :

  • Open the firefox browser
  • Navigate the AppUrl
  • Identify all Checkboxes and store into checkBoxes variable
  • Print the total checkboxes
  • Select multiple checkboxes one by one
  • Verify multiple checkboxes one by one
  • Close the current Browser window

 Selenium Code :

——————–

package seleniumProject;

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Verify_Multiple_Checkboxes {

public static void main(String[] args) {

       //open the firefox browser

WebDriver driver = new FirefoxDriver();

  //navigate the AppUrl

driver.get(“http://demo.guru99.com/test/radio.html”)

     // Identify all Checkboxes and store into checkBoxes variable

List<WebElement> checkBoxes = driver.findElements(By.xpath(“//input[@type=’checkbox’]”));

   //print the total checkboxes

System.out.println(checkBoxes.size());

for(int i=0; i<checkBoxes.size(); i++)

{

  //select multiple checkboxes one by one

checkBoxes.get(i).click();

       //verify multiple checkboxes one by one

if(checkBoxes.get(i).isSelected())

{

System.out.println(i+” checkBox is selected “);

}else{

System.out.println(i+” checkBox is not selected “);

}

}

  //Close the current Browser window  

driver.close();

}

}

SELENIUM | BROWSER COMMANDS :

isSelected(): By using this we can verify particular checkbox is selected or not on a webpage.

 

Click here: Steps to configure Selenium WebDriver with java to develop test scripts

Click here: How to handle frame in selenium webdriver using java?

Selenium Training in Hyderabad

Kosmik Technologies is on of the best selenium training in Hyderabad. We are providing lab facilities with complete real-time training. Training is based on complete advance concepts. So that you can get easily “hands-on experience”. We will give 100% job assistance.

 

What is a frame?

Frame is just like as a container where few elements can be grouped.

How to identify frame inside a webpage?

There are different ways to identify frame inside a webpage

Way 1:

  • Open webpage in a browser.

webelement in a webpage

  • Right click on webelement in a webpage

frame inside a webpage

Way 2:

  • Open webpage in a browser.
  • Right click on webelement in a webpage
  • Open source code(Html Code) of the webpage by clicking inspect element with firebug option see below image.

iframe source code

How to handle an element inside the frame?

There are 4 ways to handles frames in selenium webdriver.

Switch to frame by using index :

Method 1 :

Suppose if there is single frame in a webpage then we can switch to the iframe by using index.

Here is the sample code:

Syntax : driver.switchTo().frame(int index);

Example : driver.switchTo().frame(0);

Note : By default single frame index value ‘ 0’.That means when webpage has  only one frame then the index will be zero.

Method 2 :

Suppose if there are 3 frames in a webpage then we can switch to the iframe by using index.

Here is the sample code:

Syntax :

List<WebElement> framelist=driver.findElements(By.tagName(“iframe”));

driver.switchTo().frame(framelist.get(int index));

Example :

List<WebElement> framelist=driver.findElements(By.tagName(“iframe”));

//switchTo 1st frame by using index

driver.switchTo().frame(framelist.get(0));

  //switchTo 2nd frame by using index

driver.switchTo().frame(framelist.get(1));

//switchTo 3rd frame by using index

driver.switchTo().frame(framelist.get(2));

Switch to frame by using Id or Name :

We can also use Name and Id attributes of iframe  through which we can switch to iframes.

Here is the sample code:

Syntax 1:

driver.switchTo().frame(“Id of  the element”);

Html code :

iframe html code

                                                                                  Example : driver.switchTo().frame(“rightMenu”);

Syntax 2:

driver.switchTo().frame(“Name of  the element”);

Html code :

iframe html code

                                                                              Example : driver.switchTo().frame(“rightMenu”);

Switch to frame by using WebElement :

We can also switch to the frame using webelement.

Here is the sample code:

Syntax :

driver.switchTo().frame(WebElement);

Html code :

iframe html code

Example : driver.switchTo().frame(driver.findElement(By.name(“rightMenu”)));

How to get all the frames in a webpage ?

get all the frames in a webpage

Html code :

Open notepad and type the below Html code and save as frames.html

<html>

<body>

<iframe src=”http://www.seleniumhq.org/download/” width=”200″ height=”200″ name=”selenium”>

<p>Your browser does not support iframes.<p>

</iframe>

 

<iframe src=”http://127.0.0.1/orangehrm-2.5.0.2/login.php” width=”200″ height=”200″ name=”selenium”>

<p>Your browser does not support iframes.<p>

</iframe>

<br>

<iframe src=”http://testng.org/doc/index.html” width=”200″ height=”200″ name=”selenium”>

<p>Your browser does not support iframes.<p>

</iframe>

<br>

<a class=”gb_P” data-ved=”0EMIuCBMoAA” href=”https://mail.google.com/mail/?tab=wm” data-pid=”23″>Click on Gmail</a>

</body>

</html>

 

Example :

package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class getTotalFrames {

public static void main(String[] args) {

//   Open Firefox Browser  

       WebDriver driver = new FirefoxDriver();

 //   Open AppURL In Browser

driver.get(“file:///C:/Users/Hanumanthu/Downloads/frames.html”);

 // count all the frames on a webpage

List<WebElement> total_frames=driver.findElements(By.tagName(“iframe”));

System.out.println(total_frames.size());

//close the current browser window

driver.close();

}

}

How to verify TestNg text inside 3rd frame?

verify TestNg text inside 3rd frame

Selenium Sample Code :

package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class getTotalFrames {

public static void main(String[] args) {

   // Open Firefox Browser  

WebDriver driver = new FirefoxDriver();

//  Open AppURL In Browser

driver.get(“file:///C:/Users/Hanumanthu/Downloads/frames.html”);

 //count all the frames on a webpage

List<WebElement> total_frames=driver.findElements(By.tagName(“iframe”));

System.out.println(total_frames.size());

 //Switch to 3rd Frame by using Index

driver.switchTo().frame(total_frames.get(2));

  //Identify and get the text and store into testNg_text variable

String testNg_text=driver.findElement(By.xpath(“html/body/h2[1]”)).getText();

   //print the text from 3rd frame

System.out.println(testNg_text);

  //verify the text from 3rd frame

if(testNg_text.equals(“TestNG”))

{

System.out.println(“TestNG text verified successfully”);

}else

{

System.out.println(“TestNG text not verified successfully”);

}

 //How switch back to main window from inside any frame ?

driver.switchTo().defaultContent();

//Close the Firefox Browser

driver.close();

}

}

Note :

switch back to main window from inside any frame

1. Switch to 3rd Frame by using Index

Syntax :   driver.switchTo().frame(total_frames.get(index));

Example :   driver.switchTo().frame(total_frames.get(2));

2.Switch to 3rd  Frame by using Id

Syntax :   driver.switchTo().frame(“Id of the element”);

Example :   driver.switchTo().frame(“selenium”);

If no id then go for Name.

 3.Switch to 3rd  Frame by using Name

Syntax :   driver.switchTo().frame(“Name of the element”);

Example :   driver.switchTo().frame(“selenium”);

4.Switch to 3rd  Frame by using WebElement

Syntax :   driver.switchTo().frame(WebElement);

Example :   driver.switchTo().frame(driver.findElement(By.name(“selenium”);

 How switch back to main window from inside any frame ?

Syntax : driver.switchTo().defaultContent();

 How to handle frame in selenium webdriver using java

TestSteps:

Open Firefox Browser

Open AppURL In Browser

Get the Title of WebPage

Verify Title of WebPage

Enter the username

Enter the password

Clicking On Login Button

Identify and get  the Welcome selenium text

Verify  Welcome selenium text

Switch to frame

Handle DropDown in Selenium

  1.  How to print all the dropdown values
  2. How to Select the dropdown value inside a frame
  3. verify selected value from dropdown
  4. How to Verify dropdown values

Again switch back to main window from frame

Clicking On Logout Button

Close the Firefox Browser

Selenium Code :

package com.tests;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

importorg.openqa.selenium.support.ui.Select;

public class OrangeHRM_login {

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

// open the firefox browser

WebDriver driver = newFirefoxDriver();

// navigate the AppUrl

diver.get(“http://127.0.0.1/orangehrm-2.5.0.2/login.php”);

//Get the Title of WebPage

String title=driver.getTitle();

//print the title of the webpage

System.out.println(title);

//Verify Title of the WebPage

if (title.equals(“OrangeHRM – New Level of HR Management”)) {

System.out.println(“title is verified successfully”);

} else {

System.out.println(“title is not verified successfully”);

}

// Enter the username

  driver.findElement(By.name(“txtUserName”)).sendKeys(“selenium”);

// Enter the password

driver.findElement(By.name(“txtPassword”)).sendKeys(“selenium”);

// Clicking On Login Button

driver.findElement(By.name(“Submit”)).click();

// Identify and get  the Welcome selenium text and store into text variable

String text = driver.findElement(By.xpath(“//*[@id=’option-menu’]/li[1]”)).getText();

// Print the welcome selenium text

System.out.println(text);

//  To verify whether the welcome page successfully opened or not

if (text.equals(“Welcome selenium”)) {

System.out.println(“Welcome selenium is verified successfully”);

} else {

System.out.println(“Welcome selenium is not verified successfully”);

}

// Switch to Frame by ID

driver.switchTo().frame(“rightMenu”);

System.out.println(“****How to print all the dropdown values inside a frame****”);

Identify the dropdown

// Identify the dropdown

WebElement dropdown = driver.findElement(By.id(“loc_code”));

// Identify  dropdown values  and store into droplist  variable

List<WebElement> droplist = dropdown.findElements(By.tagName(“option”));

// How to print all the dropdown values

for (inti = 0; i<droplist.size(); i++) {

System.out.println(droplist.get(i).getText());

}

System.out.println(“*****How to Select the dropdown value inside a frame*****”);

Select the dropdown value inside a frame

/*

                    If u want to select the dropdown value then we need to create the select object for that dropdown

                    */

Select s = new Select(dropdown);

// Select the dropdown value by using index

s.selectByIndex(2);

//s.selectByVisibleText(“Emp. First Name”);

//s.selectByValue(“1”);

System.out.println(“****verify selected value from dropdown inside a frame *****”);

verify selected value from dropdown inside a frame

//get the selected value and store into selected_value variable

String  selected_value=s.getFirstSelectedOption().getText();

//print selected value

System.out.println(“selected_value  :”+selected_value);

//verify selected value from dropdown

if (selected_value.equals(“Emp. First Name”)) {

System.out.println(“selected value  verified successfully”);

} else {

System.out.println(“selected value not verified successfully”);

}

// How switch back to main window from inside any frame

driver.switchTo().defaultContent();

// Clicking On Logout Button

driver.findElement(By.xpath(“//*[@id=’option-menu’]/li[3]/a”)).click();

// Close the Firefox Browser

driver.close();

}

}

Click here: How to verify multiple checkboxes in a webpage using selenium?

Click here: Steps to configure Selenium WebDriver with java to develop test scripts

Selenium Training in Hyderabad

Kosmik Technologies is on of the best selenium training institutes in Hyderabad. We are providing lab facilities with complete real-time training. Training is based on complete advance concepts. So that you can get easily “hands-on experience”. We will give 100% job assistance.

SELENIUM

SELENIUM:

 
It is main purpose for testing and automate the web applications. It is not limited. Some of the broad web browsers publishers use on take steps for make it native part. This is the core technology in other browsers framework, automation tools and APIs. In web applications software testing framework is portable for it. In test scripting language SELENIUM provides a playback tool. It is no need for learning the script. If you write any tests it is offers test domain language. It contains the courses Scale, Ruby, Python, Groovy, Java, Perl, and PHP. These language set up Windows, Linux and micros platform. Without charge we can download and use it. Under Apache 2.0 License open source software released.
 
 SELENIUM

SELENIUM WEB DRIVER:

 
our topic used for web applications. In this programming language it used for automatic interact with the web browser to do any task. In this SELENIUM WEB DRIVER we discuss about the tools and features. Using  Firebug and IDE we can build a few scripts. These scripts moved and locating the strategies. Into the different type of web elements.
 

 FEATURES:

 
-Google Chrome
 
– Mozilla Firefox
 
– Html Unit
 
– Android Drive
 
– Internet Explorer
 
-Opera

SELENIUM COMPONENTS:

 
1. Web Driver:
 
It is very useful for Selenium. Commends are send to the browser and agreed by this. Browser-Specific driver achieved by this content. Commands are sending to a Browsers and gets results. Most of programming applications are launch and access by the browser drives. It is  known as HTML Unit browser. the driver encouraged to browse using HMTL Unit.
 
2. IDE:
 
It is complete information about integrated development environment for testing the tests. It extended through Add on Firefox and let on editing recording and testing on debugging. Recorder known as Selenium IDE. Selenium IDE is suitable with Selenium RC and it is little maintain and put down.
 
3. client API:
 
In different programming language can written in  tests an alternative written tests. This is discuss with Selenium in different methods. our programming language offers programming languages are Python, Java, Ruby, Java script and C++.
 
4. Remote Control:
 
It is also called as Selenium RC. Which agreed the commands in HTTP. It written in Java. Automated test written in web applications programming language by using RC. It is very useful for promoting Selenium Unit test frameworks.
 
5.  Grid:
 
It is a web server. Selenium grid used for remote machine running and it agreed for tests in web browser. One web server act as a hub. To know about the access on browser instance tests contact the hub. Hub has a list of web servers that provides browser instance used as tests and access.
Some programming languages are given below:
 
· Java
 
· C++
 
· Pearl
 
· PHP
 
· Python
 
· Ruby
 ADVANTAGES ON SELENIUM WEB DRIVER:
 
-It is not supported to extend the functionality and features.
 
-Not important for start executing scripts to start server prior.
 
-Testing on iPhone and android servers is support to add.
 
-Extracting the objectives is big problem. It is get to extract the object bulk.
 
-AJAX- based, Drag and Drop, and page navigation based UI elements used to support the features.
 
-Coordinates of any objects we can find through the web driver.
 
-Web driver can coordinate with testing frame work like Testing and J unit.
 
-It offers and improves reliability between browsers.
 
– Implementation of listeners is most important feature.
Online Selenium Training in Hyderabad

Online Selenium Training in Hyderabad

Course name:  Selenium

Faculty: Highly qualified and experience

About Online Selenium Training in Hyderabad

Kosmik is a Best Institute for Online Selenium Training in Hyderabad. we proud to say kosmik is one of the Best Online Selenium Training Institute in Hyderabad. we are providing Online Selenium Training in Hyderabad with Live projects. Selenium Training in Hyderabad faculty is Highly qualified and experienced. kosmik Designed Online Selenium training course in Hyderabad as per the Latest trend. kosmik provides 24*7 days Online support for the students. Our faculty is going to cover all concepts in-depth online selenium training in Hyderabad. kosmik is the right choice for Online Selenium Training in Hyderabad, India.

Highlights of the Selenium Training :

we provide course material with real-time scenarios.
we are providing classes with real time experienced faculty.
we will conduct demo sessions for students with flexible timings.
we will give 365 days technical support.
Every concept will be covered with a real-time solution.
we are also having weekend and fast track batches.
we are providing job oriented training.
we are giving placement support for the students.

Online Selenium Training in Hyderabad Course Content :

Introduction and Overview to Selenium Training

Introduction to Automation testing
Why and When it comes into the picture
supporting browsers and platforms of selenium
Basic concepts of Java
Uses of Automation Testing
Environment needs for selenium
Difference between selenium and QTP
Features of Selenium

Web Driver

web driver for selenium
web driver v/s RC
Accessing multiple browsers using web driver
Internet Explorer
Mozilla Firefox
Google Chrome
Installation and Configuring Eclipse for web driver
Constructing X path for web element using Firebug-Fire Path methods.
starts with
Parent
Ancestor
Following and preceding sibling
Normalize space
substring
Handling web elements using web driver
Handling Attributes of developer tools of Internet Explorer

Form Controls

Accessing Input box
Accessing combo Boxes using select and List
Accessing Check Box
Accessing Links

Parameterization

Accessing rows and columns of Excel sheet
Parameterization of test data using MS Excel sheet

Selenium Training in Hyderabad, Classroom & Online Training

About Selenium Training in Hyderabad

Kosmik Technologies providing best Selenium Training in Hyderabad, we are offering Classroom and Online Selenium training by real time experienced faculty. Our faculty is Certified, dedicated and Highly Qualified. Kosmik Technologies provide 24/7 days online support for the students. Our selenium Training course content designed as per the latest trend. We are offering job oriented selenium Training. We are covering each & every topic in detail and real time projects. Kosmik Technologies is the best institute for Selenium Training in Hyderabad.

Course Highlights

selenium testing tool introduction
selenium components and architecture
selenium vs other automation tools
selenium features advantages
Testing framework in selenium
eclipse framework

Selenium Architecture:

selenium RC and webdriver architecture
webdriver vs selenium RC
advantages of webdriver for selenium ide

Locator techniques in selenium:

Introduction Locator concept
About different locator techniques
selenium XPath locator contains text

Selenium IDE:

Download & Installation
record and playback in selenium
how to modify script using IDE
convert selenium ide to selenium RC
validate the locator using IDE

Selenium Setup:

step by step Explanation for setup
integration of selenium with eclipse

Selenium RC:

selenium server start
test annotation in selenium
basic selenium script

Webdriver in Selenium:

selenium webdriver setup
webdriver commands with examples
event handling in different browsers
webdriver methods in selenium
selenium webdriver programming
RC commands from webdriver
migrating selenium rc to webdriver
project structure organization

Testing Framework in Selenium:

selenium test framework design
testing annotations in selenium
testing configuration
suite execution from command prompt
testing suite parallel execution
report generation in selenium webdriver
assertion selenium
selenium verification errors
listeners concept in selenium
Preparing customized report using selenium & Java

Auto IT in selenium:

Autoit tool in selenium webdriver
create AutoIt script
au3 to Exe converter
Autoit script in selenium webdriver

Selenium Grid:

Introduction
selenium grid setup
selenium grid parallel execution
simple script execute commands