【发布时间】:2015-12-10 14:34:42
【问题描述】:
我正在尝试在 Google Chrome 中运行一部分代码,而在 Firefox 中运行其余代码
public class flip
{
static WebDriver driver = new FirefoxDriver(); // starting firefox
public static void main(String[] args) throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver1 = new ChromeDriver();
driver1.get("website1");
driver1.findElement(By.id("id_username")).sendKeys("username");
driver1.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver1.findElement(By.id("id_password")).sendKeys("password");
System.out.print("logged in");
driver1.close();
driver.get("website-2"); // in firefox
}
}
我收到以下错误(当程序需要切换浏览器时)。 两个浏览器都打开但无法驱动。
Exception in thread "main" org.openqa.selenium.WebDriverException:
f.QueryInterface is not a function
Command duration or timeout: 60.03 seconds
任何人都可以帮我解决我犯的错误吗? (firefox webdriver 必须是静态的..)
【问题讨论】:
-
几件事...我建议您更清楚地命名驱动程序变量...例如 firefoxDriver 和 chromeDriver。这样一来,您就可以清楚地知道您正在使用哪种浏览器。您没有指定错误在哪一行。
driver1.close;应该是driver1.close(); -
waht 是你的 selenium 和 firefox 版本。他们之间有冲突
-
@mahsumAkbas Firefox 40.03 和 Selenium 2.47.1
-
@JeffC 它的拼写错误
-
@jeffC 它一直在工作,直到在 driver1.close() 处关闭 Chrome 浏览器;
标签: java google-chrome firefox selenium