How to search / find all results using Selenium Java Webdriver
02:59 20 Sep 2012

Dear Selenium Webdriver Specialists,

I am new to this framework and needed a bit of advice on how to locate / find all the search results from a sales property listing website. Below is a working code which has successfully found all the properties using Selenium Webdriver but I don't know how to use findElements(by...) to pick up every results returned by this website:

    WebDriver driver = new FirefoxDriver();

    driver.get("http://www.domain.com.au/?mode=buy");

    // Enter the query string "3000"        
    WebElement query = driver.findElement(By.xpath(".//*[@id='ctl00_SearchMoreCriteria_Radar_searchToBuy']"));        
    query.sendKeys("3000");        

    WebElement searchButton = driver.findElement(By.xpath(".//*[@id='ctl00_SearchMoreCriteria_Radar_Search']")); 
    searchButton.click();  

    // Sleep until the div we want is visible or 5 seconds is over        
    long end = System.currentTimeMillis() + 5000;        

Could anyone offer some advice on this query? I also like to include a pausing mechanism before locating / finding all the returned results?

Many thanks,

Jack


Thank you Santoshsarma very much for your response but I am struggling to apply your suggestion onto the following returned web query page output snippet:

     

602/73 Flinders Lane, Melbourne

Property type
House
Bedrooms
3
Bathrooms
4
Car spaces
2
  • Main photo of 602/73 Flinders Lane, Melbourne - More Details
  • Photo of 602/73 Flinders Lane, Melbourne - More Details

List AllSearchResults=driver.findElements(By.id("ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_hypAddress"));

There is an index in ctl01 that needs to cycle through to get all search results which would be slow according other similar threats. Is there a better approach to use findElement() on a WebElement to search just its children but I am at a lost on where to locate the root. Are you able to confirm whether this approach would work & perhaps pin point where the root of the list of results from the following URL query result page: http://www.domain.com.au/Search/buy/Property/Types/Apartment-Unit-Flat/Duplex/House/New-Apartments-Off-the-Plan/New-Home-Designs/New-House-Land/Penthouse/Semi-Detached/Studio/Terrace/Townhouse/Villa/State/VIC/Area/Inner-City/Region/Melbourne-Region/Suburb/Melbourne/?bedrooms=1&bathrooms=1&carspaces=1&from=450000&searchterm=3000&pois=PriSchl|1|2|2000

Your patience for my lack of experience in this area would be very much appreciated.

selenium webdriver selenium-webdriver xpath