How To Handle Ajax Auto Suggest Drop List In Selenium Webdriver

What Is Ajax Auto Suggest Drop List?
Before learning almost how to grip ajax machine propose drib downward list In selenium webdriver software testing tool, Let me say yous what Is ajax machine propose drib downward list. If yous accept visited whatsoever software website alongside search box too that search box Is showing machine propose listing when yous type roughly affair Inside It. Simplest instance of ajax machine propose drib list Is Google search suggestion. When yous volition type something Inside It, It volition demo yous a listing of suggestions equally shown In bellow given Image.


This Is solely instance for your reference. You volition uncovering this form of ajax drib lists In many sites.

How to grip ajax drib listing In selenium WebDriver
Now supposing yous wants to select roughly value from that machine propose listing or yous wants to shop too impress all those suggestions too then how volition yous produce It?. If yous know, It Is really difficult to grip such ajax In selenium IDE software testing tools. Let nosotros endeavour to impress all those suggestions In console.

Here, Xpath designing Is same for all ajax machine propose drib listing Items. Only changing Is Value Inside <tr> tag. See bellow xpath of 1st ii Items of drib list.

//*[@id='gsr']/table/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/div/table/tbody/tr[1]/td[1]/span
//*[@id='gsr']/table/tbody/tr[1]/td[2]/table/tbody/tr[2]/td/div/table/tbody/tr[1]/td[1]/span

So nosotros volition exercise for loop(As described In my THIS POST) to feed that changing values to xpath of drib list different Items. Other ane affair nosotros postulate to reckon Is nosotros don't know how many Items It volition demo In ajax drib list. Some keywords demo yous iv Items too roughly other volition demo yous to a greater extent than than iv Items In drib list. To grip this dynamic changing list, We volition USE TRY CATCH BLOCK to choose cause of the NoSuchElementException exception if non flora side yesteryear side Item In ajax drib list.

In bellow given example, nosotros accept used testng @DataProvider annotation. If yous know, @DataProvider notation Is useful for information driven software automation testing. THIS LINKED POST volition clit yous the usage of @DataProvider notation alongside detailed instance too explanation.

Run bellow given instance In your eclipse alongside testng too run across how It Is retrieving values from ajax drib listing too impress them In console.

package Testng_Pack;  import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;  world cast Ajax_Handle {   WebDriver driver = novel FirefoxDriver();              @BeforeTest          world void setup() throws Exception {               driver.manage().window().maximize();              driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);              driver.get("http://www.google.com");      }     @AfterTest  world void tearDown() throws Exception {       driver.quit();      }     //Data provider Is used for supplying 2 unlike values to Search_Test method.  @DataProvider(name="search-data")  world Object[][] dataProviderTest(){      render novel Object[][]{{"selenium webdriver tutorial"},{"auto s"}};  }     @Test(dataProvider="search-data")  world void Search_Test(String Search){     driver.findElement(By.xpath("//input[@id='gbqfq']")).clear();    driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys(Search);    int i=1;    int j=i+1;    try{     //for loop volition run till the NoSuchElementException exception.     for(i=1; i<j;i++)       {       //Value of variable i Is used for creating xpath of drib list's unlike elements.      String proposition = driver.findElement(By.xpath("//*[@id='gsr']/table/tbody/tr[1]/td[2]/table/tbody/tr["+i+"]/td/div/table/tbody/tr/td[1]/span")).getText();      System.out.println(suggestion);      j++;            }      }catch(Exception e){//Catch block volition choose cause of too grip the exception.      System.out.println("***Please search for roughly other word***");       System.out.println();     }     } }

This means yous tin also select specific from that proposition for your searching purpose. It Is really elementary In selenium webdriver software testing tool. You tin exercise other or to a greater extent than search values In inward a higher house example. To produce It merely alter @DataProvider notation method.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM
http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post