mardi 30 octobre 2018

Finding an Element by ID Selenium Java TestNG

I'm using Selenium and TestNG for the first time and I've been trying to search an element by its ID but I keep getting an "Cannot instantiate class" error. This is my code:

import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;

public class NewTesting {

    WebDriver driver = new FirefoxDriver();

    @BeforeTest
    public void setUp() {
        driver.get("http://book.theautomatedtester.co.uk/chapter1");
    }

    @AfterTest
    public void tearDown() {
        driver.quit();
    }

    @Test
    public void testExample() {
        WebElement element = driver.findElement(By.id("verifybutton"));
    }

}

Maybe I missed installing something? I installed the TestNG plug-in for eclipse and added the WebDriver JAR files, do I need to do more? I tried following multiple tutorials but I keep getting errors, I hope someone can help. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire