Wednesday, 29 October 2014

Multi Selection

Suppose if we want to select multiple selections in the combo box. To achieve this sample code is given below.


Example: 


List<WebElement> listItems = driver.findElements("find your select by id or xpath or etc");
Actions builder = new Actions(driver);
builder.clickAndHold(listItems.get(1)).clickAndHold(listItems.get(2)).click();
Action selectMultiple = builder.build();
selectMultiple.perform();


To know FAQ's on Selenium Please ClickHere
To know SQL's Queries Required For Testers Please ClickHere

Saturday, 4 October 2014

Auto Complete Suggestion View

In an application We will search for an item in the Search box. We will try to select the third suggestion in the auto complete suggestion view. To get this sample code is given below.


package Logs;

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 Auto {

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

 WebDriver driver=new FirefoxDriver();

 driver.manage().window().maximize();

 driver.get("http://www.flipkart.com/");

// Type something on Search textbox
 driver.findElement(By.name("q")).sendKeys("mobil");

// Create object on Actions class
 Actions builder=new Actions(driver);

// find the element which we want to Select from auto suggestion

 WebElement ele=driver.findElement(By.xpath(".//*[@id='list_?']/li[3]/ac_odd"));

// use Mouse hover action for that element
 builder.moveToElement(ele).build().perform();

// Give wait for 2 seconds
 Thread.sleep(200);

// finally click on that element
 builder.click(ele).build().perform();

}
}

To know FAQ's on Selenium Please ClickHere
To know SQL's Queries Required For Testers Please ClickHere