Tag Archives: list

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

Advertisements

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;

 

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

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

Learn by examples

Learn by examples

example - Locating dynamic elements - variable class name - Locating by CSS

example – Locating dynamic elements – variable class name – 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 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;

Collection LIST

Get this code from PasteBIN

How to click on elements in iframe using Selenium web driver?

What is the problem?

How do I type into a content Editable iframe using selenium webdriver?

How to click on elements in iframe using Selenium web driver?

How to switch to iframe popup using Selenium web driver?

Solutions is: 🙂

Communication to and from Iframes

Communication to and from Iframes

 

Take this code from PasteBIN

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;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class iframeTest {
 public static void main(String[] args) throws InterruptedException {

ProfilesIni allProfiles = new ProfilesIni();
 FirefoxProfile myProfile = allProfiles.getProfile(&quot;MyTestProfile&quot;);
 myProfile.setPreference(&quot;capability.policy.default.Window.frameElement.get&quot;,&quot;allAccess&quot;);
 WebDriver myTestDriver = new FirefoxDriver(myProfile);
 myTestDriver.manage().window().maximize();

 myTestDriver.get(&quot;http://tinyurl.com/cb3lbho&quot;);
 Thread.sleep(5000L);

 try {
 List&lt;WebElement&gt; AlliFrameID = myTestDriver.findElements(By.tagName(&quot;iframe&quot;));
 System.out.println(AlliFrameID.size());
 for(int i=0;i&lt;=AlliFrameID.size();i++){
 System.out.println(AlliFrameID.get(i).getAttribute(&quot;id&quot;));
 }
 } catch (Exception e) {

 myTestDriver.switchTo().frame(&quot;ifrm&quot;);

 myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[2]/input&quot;)).click();

 System.out.println(myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[1]/input&quot;)).getAttribute(&quot;value&quot;));

 myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[3]/input&quot;)).click();
 System.out.println(myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[1]/input&quot;)).getAttribute(&quot;value&quot;));

 myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[3]/input&quot;)).click();
 System.out.println(myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[1]/input&quot;)).getAttribute(&quot;value&quot;));

 myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[3]/input&quot;)).click();
 System.out.println(myTestDriver.findElement(By.xpath(&quot;//*[@id='ifrmTest']/p[1]/input&quot;)).getAttribute(&quot;value&quot;));

 myTestDriver.switchTo().defaultContent();
 myTestDriver.findElement(By.xpath(&quot;//*[@id='testForm']/p/input[1]&quot;)).sendKeys(&quot;Online selenium Training&quot;);

 myTestDriver.findElement(By.xpath(&quot;//*[@id='testForm']/p/input[2]&quot;)).click();
 }

 }

}

 

myTestDriver.switchTo().frame

myTestDriver.switchTo().frame

What are the Locating Techniques dynamic XPATH patterns / Managing variable xpaths using selenium webdriver ?

Problem:

What are the Locating Techniques dynamic XPATH patterns / Managing variable xpaths using selenium webdriver ?

 

How to Solve this?

What are the Locating Techniques dynamic XPATH patterns / Managing variable xpaths 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 DynamicXpath {

 public static void main(String[] args) throws InterruptedException {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://tinyurl.com/cn5pum8");
 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

List<WebElement> RadioNamelist = myTestDriver
 .findElements(By
 .xpath("//input[contains(@id,'-real')]"));

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

 for(int i=0;i<RadioNamelist.size();i++){
 System.out.println(RadioNamelist.get(i).getAttribute("name"));
 }
 myTestDriver.quit();
 }

&nbsp;

}

Get this code from PasteBin

What are the Locating Techniques dynamic XPATH patterns / Managing variable xpaths using selenium webdriver ?

 

public java.util.List findElements(By by)

public java.util.List findElements(By by)

Collection LIST

How to deal with checkbox webelement using selenium webdriver?

Problem:

How to deal with checkbox webelement using selenium webdriver?

Solution:

How to deal with checkbox webelement using selenium webdriver?

How to deal with checkbox 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 testCheckox {
public static void main(String[] args) throws InterruptedException {
WebDriver myTestDriver = new FirefoxDriver();
myTestDriver.get("http://tinyurl.com/yj9jgo");
myTestDriver.manage().window().maximize();
myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
List<WebElement> CHECKBOXlist = myTestDriver
.findElements(By
.xpath("//input[@type='CHECKBOX']"));

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

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

Thread.sleep(50000L);

myTestDriver.quit();
}

}

Get this code from PasteBIN

How do I get length of list of lists in Java?

How do I get length of list of lists in Java?

Collection LIST

public java.util.List findElements(By by)

public java.util.List findElements(By by)

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 parameterize test in junit with example

@Parameters

The custom runner Parameterized implements parameterized tests. When running a parameterized test class, instances are created for the cross-product of the test methods and the test data elements.

 how to convert array to list in java ?

package myWorkjUnit;

import java.util.Arrays;
import java.util.List;

public class ArrayToList {
 public static void main(String[] argv) {

 String sArray[] = new String []{"Array A", "Array B", "Array C"};

 //convert array to list
 List<String> lList = Arrays.asList(sArray);

 System.out.println(lList);

 }

}

package myWorkjUnit;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/*Structure of a parameterized test class

1. A static method that generates and returns test data,
2. A single constructor that stores the test data, and
3. A test.
*/

@RunWith(value = Parameterized.class)
public class ParameterizedTestExample {
 private int number1;

 /*
 * Constructor.
 * The JUnit test runner will instantiate this class once for every
 * element in the Collection returned by the method annotated with
 * @Parameters.
 */

 public ParameterizedTestExample(int number) {
 this.number1 = number;
 }

 /*
 * Test data generator.
 * This method is called the the JUnit parameterized test runner and
 * returns a Collection of Arrays. For each Array in the Collection,
 * each array element corresponds to a parameter in the constructor.
 */
 @Parameters
 public static Collection<Object[]> data() {

// In this example, the parameter generator returns a List of
// arrays. Each array has two elements: { datum, expected }.
// These data are hard-coded into the class, but they could be
// generated or loaded in any way you like.
 Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };

 //convert array to list
 return Arrays.asList(data);
 }

/*
 * The test.
 * This test method is run once for each element in the Collection returned
 * by the test data generator -- that is, every time this class is
 * instantiated. Each time this class is instantiated, it will have a
 * different data set, which is available to the test method through the
 * instance's fields.
 */
 @Test
 public void pushTest() {
 System.out.println( "Parameterized Number is : " + number1);
 }
}

</pre>
Parameterized Number is : 1
Parameterized Number is : 2
Parameterized Number is : 3
Parameterized Number is : 4
<pre>


 

 

References

References

 

 

 

 

 

 

References:

Parameterized (JUnit API)

Link 1 Link 2 Link 3 Link 4 Link 5

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

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

Topics

.Net Core, AspNetCore, Entity Framework, Entity Framework Core, AspNetIdentity, AspNetIdentityCore, Unit Test, WCF, Workflows

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