Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with FirefoxDriver


Everything we need to use in FirefoxDriver is bundled with the Java client bindings, which we used in Chapter 5, Design Patterns. This makes the driver easy to use.

We will do the basic task of loading the browser and type the following into the page:

  1. Update the setUp() method to load FirefoxDriver();.

    driver = new FirefoxDriver();
  2. Now we need to find an element. In this section, we will find the one with the nextBid ID:

    WebElement element = driver.findElement(By.id("nextBid"));
  3. Now we need to type the following line of code into that element:

    element.sendKeys("100");
  4. Run your test and it should look like the following:

    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.*;
    import org.testng.annotations.*;
    
    public class TestChapter6 {
    
      WebDriver driver;
    
      @BeforeTest
      public void setUp(){driver = new FirefoxDriver();
        driver.get("http://book.theautomatedtester.co.uk/chapter4");
      }
    
      @AfterTest
      public void tearDown(){
        driver.quit();
      }
    
      @Test...