O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – starting Google Chrome or Chromium

Imagine that you wanted to work with Google Chrome to get an attribute of an element on the page. To do this we will need to instantiate a ChromeDriver. Let's see an example.

  1. Update the setUp() method to load the ChromeDriver():
    driver = new ChromeDriver();
  2. Now we need to find an element. In this section we will find the one with the ID selectLoad:
    WebElement element = driver.findElement(By.id("selectLoad"));
  3. Now we need to get the value attribute of that element:
    element.getAttribute("value");
  4. Run your test and it should look like the following:
    public class TestChapter6 { WebDriver driver; @Before public void setUp(){ driver = new ChromeDriver(); driver.get("http://book.theautomatedtester.co.uk/chapter4"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required