我一直在使用 selenium IDE 和 webdriver。 我在 eclipse 中编写了一个小型 java 程序,它启动 Mozilla 浏览器并转到 Google 并无限次搜索关键字。该程序在我的电脑(Windows 7,JDK - 1.8_40)中运行,但是当我创建一个可执行文件并在我的笔记本电脑(Windows 8.1)中尝试它时,它打开了浏览器,但页面屏幕上没有显示任何内容。
可执行 jar 在我创建 jar 文件的电脑中运行。 代码如下:
package Test1;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args)
{
WebDriver driver;
String appURL = "http://www.google.com";
driver = new FirefoxDriver();
driver.get(appURL);
for(int i = 0; i < 1;)
{
driver.findElement(By.id("lst-ib")).clear();
driver.findElement(By.id("lst-ib")).sendKeys("selenium");
driver.findElement(By.name("btnG")).click();
driver.findElement(By.id("lst-ib")).clear();
driver.findElement(By.id("lst-ib")).sendKeys("this is a test");
driver.findElement(By.name("btnG")).click();
}
}
}
最佳答案
这意味着 FireFox 驱动程序(它基本上是一个使用 Selenium 与之交互的代理工具)未覆盖您的 Firefox 版本。所以问题是 - 您拥有哪个版本的 Firefox 驱动程序和 Firefox 本身?
关于java - 如何在不同的PC上运行jar文件(具有selenium自动化、webdriver),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29415060/