java - 为什么我无法处理两个浏览器?

标签 java google-chrome firefox selenium

我正在尝试在 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 必须是静态的..)

最佳答案

将 http://放在 Firefox 驱动程序网址的开头。这是该 Selenium 版本中的义务。

关于java - 为什么我无法处理两个浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32567387/

相关文章:

java - Java中解析Json对象

css - chrome新版打印隐藏部分的打印预览边距

java - 获取 "$ is not defined"

firefox - 如何开发 Firefox 插件?

java - (Dis)由于语言内部结构,证明一种算法比另一种算法运行得更快

使用 SNMP 监视 Java 应用程序

java - 需要使用什么正则表达式从 HTML 标记中提取特定值?

javascript - 无法加载 chrome 中 500 内部服务器错误的响应

python - 通过 Python 使用 Selenium 进行多处理时,Chrome 在几个小时后崩溃

javascript - jQuery AJAX 数据类型 : 'script' not working on firefox