Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

selecting search item values in drop down using selenium webdriver Empty selecting search item values in drop down using selenium webdriver

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.
avatar
Sourav
Active particpant
Active particpant
Posts : 17
Join date : 2012-06-28

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

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
avatar
anemuday
Active particpant
Active particpant
Posts : 11
Join date : 2012-10-11

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

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

selecting search item values in drop down using selenium webdriver Empty 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