我正在为Netbeans 8.2中的Booth's Multiplication编写一个程序作为JAVA Web应用程序。我使用的是selenium-server-standalone-2.50.1.jar和Firefox 46。
当我编写代码并运行它时,它只是打开页面但没有测试发生。请帮忙。
/*
* 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();
}
}
我的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>
答案 0 :(得分:-2)
<强>更新:强>
如果您使用selenium 3.0.1
或更高版本,那么JAVA版本也应为1.8,您需要使用geckodriver
来运行Firefox
。 (在这种情况下,请确保使用所有必需组件的最新版本)
否则,您需要将Selenium版本升级到3.0 or higher
。