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
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
No comments:
Post a Comment