Share
Go down
dhivyaavk
Posts : 2
Join date : 2012-01-02

selecting search item values in drop down using selenium webdriver

on Fri Sep 21, 2012 5:30 pm
Hi,

I am new to selenium and i have coded using selenium webdriver.But i am not able to proceed please guide me for this scenario.

1.go to www.google.com.
2.Type cheese in the search box .It will display the respective cheese items like drop down in search box.In which i have to select cheese recipes.I am not able to proceed after the cheese.I dont know how to code for selecting the cheese recipes.Please guide me to proceed.i have been trying by selecting xpath and all but i dnt know how to do.
Sourav
Active particpant
Active particpant
Posts : 17
Join date : 2012-06-28

Re: selecting search item values in drop down using selenium webdriver

on Mon Oct 08, 2012 6:08 pm
Hi,
Whatever drop down you are seeing, its not simple drop down, its dynamic in nature. Try something simple as a new
anemuday
Active particpant
Active particpant
Posts : 11
Join date : 2012-10-11

Re: selecting search item values in drop down using selenium webdriver

on Fri Oct 19, 2012 5:29 pm
Hi,

Below is my approach:
Code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Forum_Google_Search
{
    public static void main(String[] args)
    {
        String str1,str2;
        str1="cheese";
        str2="cheesecake recipes";
        String str_xpath=null;
        boolean found=false;
       
       
        WebDriver driver= new FirefoxDriver();
        driver.get("http://www.google.com");
       
        WebElement obj_Search=driver.findElement(By.id("gbqfq"));
        obj_Search.sendKeys(str1);
       
        try {
            Thread.sleep(5000);
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
       
       
        int no_elements=driver.findElements(By.xpath("//*[@class='gssb_m']/tbody/tr")).size();
        for(int i=1;i<=no_elements;i++)
        {
            str_xpath="//*[@class='gssb_m']/tbody/tr["+i+"]";
            String x=driver.findElement(By.xpath(str_xpath)).getText();
            if(x.equals(str2))
            {
                found=true;
                break;
            }
        }
       
        if(found==true)
        {
            WebElement obj_lookingString=driver.findElement(By.xpath(str_xpath));
            obj_lookingString.click();
            System.out.println("Clicked on the link :"+str2);
        }
        else
        {
            System.out.println("Not able to find the link :"+str2+" mentioned");
        }
    }

}
Sponsored content

Re: selecting search item values in drop down using selenium webdriver

Back to top
Permissions in this forum:
You cannot reply to topics in this forum