Technical Project Lead @ Huawei Technologies

My photo
Bangalore/Hyderabad, Karnataka/Andhra Pradesh, India
Have an overall 13 + yrs of experience Currently working as an Senior Architect.Expertise in design,implementation of Automation frameworks for Opensource automation tools like Selenium,Jmeter, Webdriver,Appium, Robotium Expertise in integrating Test & ALM Management tools like Rally,Qmetry,JIRA-Zephyr with Automation frameworks Expertise in design and developmenet Mobile Automation frameworks for tools like Appium, Robotium Remote Control,Cucumber BDD,Manual Testing

Followers

Saturday, August 10, 2013

How to verify Google Search List Options using Selenium RC/ Webdriver

Below is the snippet for list the google search list options using both Selenium RC and web driver


package selenium;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.Selenium;

public class GoogleTests {
    static WebDriver driver;
    public static void main(String[] args) throws InterruptedException {
        driver = new FirefoxDriver();
        driver.get("http://www.google.co.in");
        driver.findElement(By.xpath("//input[@type='text']")).sendKeys("Selenium webdriver");
         // Selenium Code to print all the options from the dropdown suggestionlist
        Selenium selenium = new WebDriverBackedSelenium(driver,
                "http://www.google.co.in");
        Thread.sleep(2000);
        System.out.println("Below list is printed by Selenium RC");
        int listCount = selenium.getXpathCount(
                "//table[@class='gssb_m']/tbody/tr").intValue();
        for (int i = 1; i < listCount; i++) {
            String listValues = selenium
                    .getText("//table[@class='gssb_m']/tbody/tr[" + i
                            + "]/td[1]/div/table/tbody/tr[1]/td[1]/span");
            System.out.println(listValues);
        }
        // Webdriver Code to print all the options from the dropdown suggestion list
        System.out.println("Below list is printed by Webdriver");
        List<WebElement> options = driver.findElements(By
                .xpath("//table[@class='gssb_m']/tbody/tr"));
        for (WebElement webElement : options) {
            System.out.println(webElement.getText());
        }
        // driver
        driver.close();
        driver.quit();

    }

}

3 comments:

  1. Fantastic article ! You havemade some very astute statements and I appreciate the the effort you have put into your

    writing. Its clear that you know what you are writing about. I am excited to read more of your sites content.

    Microsoft dynamics training

    ReplyDelete
  2. Hi Kiran,
    We have requirement like as soon as the application build deployment has been done, need to execute my jenkin jobs automatically.
    Please suggest me on this.

    Thanks,
    Mahesh

    ReplyDelete
    Replies
    1. Hi Mahesh, You can do the Jenkins integration by having your Selenium Project with Ant/Maven and its just few steps to setup Jenkins

      Delete