Tag Archives: Selenium / WebDriver API

Selenium Web Driver : Handle Confirm Box

Please Refer this blog entry

Example for selenium webdriver – with PrestaShop’s free ecommerce

Example 1

 

Get this code from PASTEBIN

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class testPrestashopExample {
 public static void main(String[] args) {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.manage().window().maximize();

 myTestDriver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
 myTestDriver.get("http://tinyurl.com/cb6llp3");

 // Click on Electronic menu option
 myTestDriver.findElement(By.xpath("//*[@id='header']/div[2]/ul/li[3]/a")).click();




 try {
 // Loop throgh all products till get "iPhone 4S" name
 for (int i = 1; i < 9; i++) {
 if(myTestDriver.findElement(By.xpath("//*[@id='product_list']/li["+i+"]/div[2]/h3/a")).getText().equals("iPhone 4S")){

 // click on "iPhone 4S" named product
 myTestDriver.findElement(By.xpath("//*[@id='product_list']/li["+i+"]/div[3]/a")).click();

 }
 }

} catch (Exception e) {

 }


 }
 }

&nbsp;

 

jQuery with selenium webdriver – Example of Drag and drop with jQuery UI

Example :

jQuery with selenium webdriver – Example of Drag and drop with jQuery UI

Drag and drop with jQuery UI

Drag and drop with jQuery UI

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;
import org.openqa.selenium.interactions.Actions;
public class testjquerydraganddrop {
 private static WebDriver myTestDriver;

 public static void main(String[] args) {


 myTestDriver = new FirefoxDriver();

 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(1L,TimeUnit.SECONDS);
 myTestDriver.get("http://dev.css-zibaldone.com/onwebdev/post/jquery-drag-and-drop.html");

 WebElement draggable = myTestDriver.findElement(By.id("draggable"));

 WebElement droppable = myTestDriver.findElement(By.id("droppable"));

 new Actions(myTestDriver).dragAndDrop(draggable, droppable).build().perform();
 }

}


Drag and drop with jQuery UI

how to handle javascript alert in selenium webdriver?

What is your Problem?

how to handle javascript alert in selenium webdriver?

 

Solution:

What is Javascript alert?

[Example 1] [Example 2] [Example 3]

how to handle javascript alert in selenium webdriver?

how to handle javascript alert in selenium webdriver?

 

Take a example code from PasteBIN

 

import java.util.concurrent.TimeUnit;

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

 Thread.sleep(1000L);
 myTestDriver.switchTo().alert().accept();

 myTestDriver.close();

}

}

how to handle popups in selenium webdriver ?

Problem>

How [Pop up handling in Selenium Webdriver using SET and Iterator and switchTo]?

Solution:

popup 2

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class showModalDialog {
 public static void main(String[] args) {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://tinyurl.com/6abw");
 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

 // Create the set
 Set<String> codeprojectWindowID = myTestDriver.getWindowHandles();
 System.out.println("Main Window Handle ----------------- " + codeprojectWindowID);
 Iterator<String> it = codeprojectWindowID.iterator();

 while (it.hasNext()) {
 // Get element
 Object element = it.next();
 System.out.println(element);
 }

 myTestDriver.findElement(By.xpath("//*[@id='ctl00_Bn']/tbody/tr[1]/td[3]/div/div[3]/span/span/a")).click();
 myTestDriver.findElement(By.xpath("//*[@id='ctl01_MC_MemberLogOn_OpenAuth']/a[2]/img")).click();
 System.out.println("Stand on " + myTestDriver.getTitle() + " Page");

 codeprojectWindowID = myTestDriver.getWindowHandles();
 it = codeprojectWindowID.iterator();
 String MainWindowHandle = it.next();
 String NewWindowHandle = it.next();
 System.out.println(MainWindowHandle);
 System.out.println(NewWindowHandle);

 //Thread.sleep(3000L);

 // go to Google Accounts Window
 myTestDriver.switchTo().window(NewWindowHandle);

 System.out.println("Stand on " + myTestDriver.getTitle() + " Page");
 //Click on Can't access your account?
 myTestDriver.findElement(By.xpath("//*[@id='link-forgot-passwd']")).click();

 // Go to 3rd popup window and click on Submit button - Google Account Recovery

 codeprojectWindowID = myTestDriver.getWindowHandles();

 it = codeprojectWindowID.iterator();
 it.next();
 it.next();

 String NewPopUPWindow = it.next();

 // Go to Google Account Recovery
 myTestDriver.switchTo().window(NewPopUPWindow);
 System.out.println("Stand on " + myTestDriver.getTitle() + " Page");

myTestDriver.findElement(By.xpath("//input[@class='button g-button g-button-submit']")).click();

 System.out.println("Good bye " + myTestDriver.getTitle() + " Page");
 // Close all Opened windows

// close Google Account Recovery
 myTestDriver.close();

 // go to Google Accounts window
 myTestDriver.switchTo().window(NewWindowHandle);
 System.out.println("Good bye " + myTestDriver.getTitle() + " Page");

 // Close Google Accounts Window
 myTestDriver.close();

 // GO to Member Log-on - CodeProject window
 myTestDriver.switchTo().window(MainWindowHandle);
 System.out.println("Good bye " + myTestDriver.getTitle() + " Page");
 //Close Member Log-on - CodeProject window
 myTestDriver.close();

}

}

Get this code from PasteBIN

Console OutPut

Main Window Handle ----------------- [{6997804e-3b34-4b5b-9e91-08247a4594ad}]
{6997804e-3b34-4b5b-9e91-08247a4594ad}
Stand on Member Log-on - CodeProject Page
{6997804e-3b34-4b5b-9e91-08247a4594ad}
{ead76434-1825-491a-a264-43f6ea892f6b}
Stand on Google Accounts Page
Stand on Google Account Recovery Page
Good bye Google Account Recovery Page
Good bye Google Accounts Page
Good bye Member Log-on - CodeProject Page

popup

what is difference between findElements and findElement selenium Webdriver?

Problem:

what is difference between findElements and findElement selenium Webdriver?

Solution:

findElement

findElement

  • findELement will find the first matching element.
  • findELement – will throw NoSuchElementException if no matching element found
  • findElement() method will throw NoSuchElementException if it couldn’t able to find the element with the specified locator .
  • public WebElement findElement(By by)

findElements 

findElements

  • findELements will all the matching elements. You’ll probably need to loop through all the elements returned. I’m sure there’s a concrete examples of this on the wiki, if nto google.
  • findELements – will return a empty list if no matching elements found and no exception will be thrown
  • findElements() will return empty list if it couldn’t able to find the element with the specified locator.
  • public java.util.List<WebElement> findElements(By by)

Collection LIST

Example of FindElements

Starting Chrome Browser using selenium WebDriver(Selenium2) with example

Please Refer this blog entry

Please Refer this blog entry

How to start chrome browser using selenium webdriver?

Please Refer this blog entry

Please Refer this blog entry

How to run Google Chrome with Selenium WebDriver?

 

 

Problem:

We want to Run all our testcases using Google Chrome browser using selenium Webdriver.

 

Solution:

 

Lets try to open Chrome as we open firefox using selenium WebDriver.

 

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class ChromeDriver1 {
 public static void main(String[] args) {

 WebDriver driver = new ChromeDriver();
 driver.manage().window().maximize();
 driver.get("http://google.com");
 }

}

 

When Run above code we get following error >>>>

The path to the driver executable must be set by the webdriver.chrome.driver system property

The path to the driver executable must be set by the webdriver.chrome.driver system property

 

 

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
 at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
 at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
 at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:69)
 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
 at ChromeDriver1.main(ChromeDriver1.java:8)

 

What this error try to explain.

That says that to run chrome using selenium webdriver. We have to follow following 2 steps:

1. Download ChromeDriver server for win

2. Set system property

Download chromedriver.exe and put this in appropriate driver. We put in C:/ drive for our example.

 

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeDriver1 {
 public static void main(String[] args) {

//Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined "properties"; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.
 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
 driver.manage().window().maximize();
 driver.get("http://google.com");
 }

}

 

 

 

selenium flash automation

Please Refer this blog entry

Please Refer this blog entry

Pupunzi

For a better web

Tech

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

Digital Inspiration

Technology, Software and Internet

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

Different Journeys

Let's make life easier!

Thinking in Silverlight

Silverlight/WPF/Windows 8 Store App

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, Linux, Arm processors, Embedded OS, Photography, Scouts BSA, Cloud, and other things that interest me

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

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 and High paid jobs for well Experienced IT professionals on Referal jobs.

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

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

Mindscripts Software Testing Training Institutes In Pune

Software Testing In Pune, Software Testing Training In Pune, Software Testing Training Institute,Software Testing Training Institutes In Pune ,Software Testing Training Centers,Software Testing Classes In Pune,,Software Testing Courses Pune, Software Testing Certification In Pune,,software testing certification course in pune,software testing certification institutes in pune

edington associates

Working with organizations to develop sustainable and thriving workplaces and people.

Main Admin Site for the WPVIP multisite

This multisite hosts public sites for Parse.ly and WordPress VIP

WORK Online

Virtual Office at HOME

SysfoData

Software Development, Web Development and Internet Marketing Service Available here.

Birth Pangs of a Startup

Virtual Assistance, Startups, Technology, Online Work and More