Search code examples
seleniumselenium-webdrivernetbeans-8

Selenium Test doesn't run


I'm writing a program for Booth's Multiplication as a JAVA Web Application in Netbeans 8.2. I am using selenium-server-standalone-2.50.1.jar and Firefox 46.

When I write my code and run it, it just opens the page but no tests happen. Please help.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * 
 */

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class booth {
    private WebElement element, element1;
    public String str;

    public void Mul_Positive(){
        WebDriver driver = new FirefoxDriver();
        driver.get("http://localhost:8080/BoothsMul/index.html");
        element = driver.findElement(By.xpath("//input[@name='t1']"));
        element.sendKeys("2");
        str = driver.findElement(By.xpath("//input[@name='t1']")).getText();

        System.out.println(str);

        element1 = driver.findElement(By.xpath("//input[@name='t2']"));
        element1.sendKeys("5");
        str = driver.findElement(By.xpath("//input[@name='t2']")).getText();

        System.out.println(str);

        driver.findElement(By.xpath("//input[@name='submit']")).click();
        driver.quit();
    }

    public void Mul_Negative(){
        WebDriver driver = new FirefoxDriver();
        driver.get("http://localhost:8080/BoothsMul/index.html");
        element = driver.findElement(By.xpath("//input[@name='t1']"));
        element.sendKeys("c");
        str = driver.findElement(By.xpath("//input[@name='t1']")).getText();

        System.out.println(str);

        element = driver.findElement(By.xpath("//input[@name='t2']"));
        element.sendKeys("5");
        str = driver.findElement(By.xpath("//input[@name='t2']")).getText();

        System.out.println(str);

        driver.findElement(By.xpath("//input[@name='submit']")).click();
        driver.quit();
    }

    public static void main(String[] args){
        booth b = new booth();

        b.Mul_Positive();
        b.Mul_Negative();

    }
}

My index.html

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <body>

        <form name='f1' action='http://localhost:8080/BoothsMul/Boothmul' method='get'>
First No. <input type='text' name='t1'><br>
Second No. <input type='text' name='t2'><br>
<input type='submit' name='submit' value='submit'>
        </form>
    </body>
</html>

Solution

  • UPDATED:

    If you're using selenium 3.0.1 or higher then JAVA version should be 1.8 also, you'll need to make use of geckodriver to run Firefox. (Make sure you are using latest versions of all the required component in this case)

    Else, you need to upgrade your Selenium Version to 3.0 or higher.