Tag Archives: Locators

example 3 – Locating dynamic elements – variable class name – Locating by CSS

example 3 – Locating dynamic elements – variable class name – Locating by CSS

Learn by examples

Learn by examples

 

get this code from pasteBIN

Collection LIST

 

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 TestLocatingDynamicElementsbutton {
 public static void main(String[] args) {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://tinyurl.com/buxk9dg");
 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

List<WebElement> ButtonNamelist = myTestDriver
 .findElements(By
 .cssSelector("span[class^='z-button']"));

System.out.println(ButtonNamelist.size());
 for(int i=0;i<ButtonNamelist.size();i++){
 System.out.println(ButtonNamelist.get(i).getText());
 }


 myTestDriver.quit();

 }

 }

&nbsp;

 

Output

 

5
Left
Right
Above
Below
Big Button

example – Locating dynamic elements – variable class name contains text – Locating by CSS

example – Locating dynamic elements – variable class name contains text – Locating by CSS

Learn by examples

Learn by examples

 

Get this code from PASTEBIN

Output -  example – Locating dynamic elements – variable class name contains text – Locating by CSS

example – Locating dynamic elements – variable class name contains text – Locating by CSS

 

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 TestLocatingDynamicElementscheckbox {
 public static void main(String[] args) {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://tinyurl.com/d7ovu8z");
 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

List<WebElement> checkboxlist = myTestDriver
 .findElements(By
 .cssSelector("span[class*='checkbox']"));

System.out.println(checkboxlist.size());
 for(int i=0;i<checkboxlist.size();i++){
 System.out.println(checkboxlist.get(i).getText());
 }


 myTestDriver.quit();

 }
 }

&nbsp;

 

How to deal with radiobutton webelement using selenium webdriver?

Problem:

How to deal with radiobutton webelement using selenium webdriver?

Solution:

Example Site Image

How to deal with radiobutton webelement using selenium webdriver

How to deal with radiobutton webelement using selenium webdriver

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 TestRadioButtons {
 public static void main(String[] args) throws InterruptedException {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_RADIO.html");

 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

 List<WebElement> RadioGroup1 = myTestDriver.findElements(By.name("pizzasize"));

 for(int i =0; i < RadioGroup1.size() ; i++ ){
 System.out.println(RadioGroup1.get(i).isSelected());
 }

 RadioGroup1.get(2).click();

 for(int i =0; i < RadioGroup1.size() ; i++ ){
 System.out.println(RadioGroup1.get(i).isSelected());
 }

 Thread.sleep(50000L);

myTestDriver.quit();
 }

}

How to deal with Dropdown/weblist webelement using selenium Webdriver?


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DropDownTest {

 public static void main(String[] args) {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://www.shine.com/partnersites/");
 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
 // DropDown
 myTestDriver.findElement(By.className("cls_ulAdvSearch_a")).click();

 myTestDriver.findElement(By.xpath("//*[@id='id_ffunc_area_text']")).sendKeys("Quality / Testing (QA-QC)");
 myTestDriver.findElement(By.xpath("//*[@id='id_findustry']")).sendKeys("IT - Software");

 myTestDriver.findElement(By.xpath("html/body/div[3]/div[3]/form/div/ul[2]/li[5]/input[2]")).click();

 List<WebElement> Industry = myTestDriver.findElement(By.id("id_ffunc_area_text")).findElements(By.tagName("option"));

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

 for(int i = 0; i< Industry.size();i++){
 System.out.println(Industry.get(i).getText() +"--------------> "+ Industry.get(i).getAttribute("value"));
 }

 myTestDriver.quit();
 }
}

 

Collection LIST

how to locating Locating by CSS using selenium IDE?

Please refer this blog – Link

how to locating Locating by Id using selenium IDE?

Please refer this blog – Link

how to locating Locating by Name using selenium IDE?

Please refer this blog – Link

how to locating Locating by XPath using selenium IDE?

Please refer this blog – Link

how to locating Locating Hyperlinks by Link Text using selenium IDE?

Please refer this blog – Link

How to use Locator Assistance to get other options to identify the webelement in selenium IDE?

Follow this blog entry before read this blog > Read ME

Target is used to identify webelement on the webpage

How many types for Locating Elements on the webpage?

Locating by Id / Locating by Name / Locating by XPath / Locating Hyperlinks by Link Text / Locating by CSS

We need to install two addons in firefox before moving forward

Firebug :: Add-ons for Firefox

FirePath :: Add-ons for Firefox

Using this addon we can get all details of webpage.

Locating by Id

Lets go on to WordPress web portal – http://demo.opensourcecms.com/wordpress/wp-login.php

We want to find Username textbox element on the webpage using ID of that element

For that start firebug.

use web element inspector to get location of Username element on the webpage.

We get following code for it. in which one attribute  id=”user_login” which is used to identify Username field at run time.

<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" name="log" style="background-color: rgb(251, 251, 251);">

Locating by Name

Using Name of the webelement we get access of that at runtime.

In wordpress example name=”log” 

<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" name="log" style="background-color: rgb(251, 251, 251);">

🙂 Locating by XPath 🙂 

Very useful…………..

For this we will firebug + firepath.

There are two ways of accessing element using xpath:

  1. absolute XPATH
  2. Relative XPATH

On wordpress website we get both as following to identify element

//*[@id='user_login']

 

html/body/div[1]/form/p[1]/label/input

We mostly use identical / relative xpath identify web element on the page.

Locating by XPath

Locating by XPath

Locating by XPath – By finding a nearby element with an id or name attribute (ideally a parent element) you can locate your target element based on the relationship

Locating Hyperlinks by Link Text

 <a title="Password Lost and Found" href="http://demo.opensourcecms.com/wordpress/wp-login.php?action=lostpassword" style="background-color: transparent;">Lost your password?</a>

 

 

Locating by CSS

What is CSS?

  • CSS stands for Cascading Style Sheets
  • Styles define how to display HTML elements

So in our wordpress example, Login page webelements has given some css

  • class=”input”
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" name="log" style="background-color: rgb(251, 251, 251);">

 

If we want to identify webelement using CSS given to it We should enter following values into Target field

css=input[type=”password”]

 

<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" name="pwad">

 

Pupunzi

For a better web

Tech

News and reviews from the world of gadgets, gear, apps and the web

VentureBeat

News About Tech, Money and Innovation

Digital Inspiration

Tips and tutorials around all things tech.

Thinkwareglobal's Blog

Just another WordPress.com weblog

Kenazari's Blog

Just another WordPress.com weblog

Richfowler1's Blog

Just another WordPress.com weblog

Romaicus's Blog

Just another WordPress.com weblog

botlaguduri

Just another WordPress.com site

chandanag89

Just another WordPress.com site

meghshetty

Just another WordPress.com site

digitalmediaexpert

digital media expert blog

Thinking in Silverlight

Silverlight/WPF/Windows 8 Store App

Different Journeys

Let's make life easier!

LAW RESOURCE INDIA

LEGAL RESOURCE CENTRE / COURT JUDGMENTS / LEGAL ARCHIVES

BookConnect

Promoting Indian language Books

Mary Ann M-P's Blog

Selenium: My Take

Actively Lazy

Software, crafted with passion

SAPonPower

An ongoing discussion about SAP infrastructure

SAP Career

Your Career Mentor

hrsapcertification

Just another WordPress.com site

The secret product manager

Thoughts about product management, SUSE, Linux, ARM processors, Cloud, AIX, Power Systems, and other things that interest me

Sap Certification Material . Com

Quality store for sap software and courses

Simon Les Flex's Blog

SAP Process Integration Specialist - NOW WE CAN DO BETTER!

Oracle Technologies Primer

An Oracle Fusion Middleware and iPaaS blog!

Gilberto Holms

Java, Middleware, SOA Architecture Blog

The Skeleton

Java code skeletons, tips and pointers

J@n van Zoggel

integration, innovation & random technology stuff

The Pragmatic Integrator

Hints and tips from a pragmatic integration specialist

briskwalk

The pace of life..

Optimalbg's Blog

Just another WordPress.com site

IT Jobs in USA

Keep the track of this Blog if you are looking out for some good Opportunities to work in USA....

Referral Jobs | Right Place to Get a Job

Hurry you are one Click away to get a job - Fresher Jobs for 2012, 2013 fresher’s and also high paid jobs for well Experienced IT professionals on Referal jobs.

eccinternational.wordpress.com/

ISO Consulting | ISO 27001 | ISO 20000 | CMMI | BCM | GRI Sustainability Reporting & Assurance | eLearning | Trainings | Philippines

Michael Korn's Blog

Musings on Life, Career, Faith and Technology

WORKINGWITHQTP

Just another WordPress.com weblog

Solutions365

.net, WCF, Unity, IOC, SQL

SQA and Testers Blog

Just another WordPress.com weblog

Expertqtp's Weblog

Just another WordPress.com weblog

Sai Chamarthi

Experienced Testing Professional

saxenavinay

A great WordPress.com site

Suresh4qtp's Blog

Just another WordPress.com site

jonah95hill

This WordPress.com site is the cat’s pajamas

It's always something...

Just another WordPress.com weblog

Faculty of Information Technology - Lê Ngọc Tiến

Be Yourself! Simplify Our Goals! Nothing is Impossible!

Anti-Malware Testing

Thoughts on security product testing past and present

Methods & Tools

Practical knowledge for the software developer, tester and project manager