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

时间:2015-09-14 14:29:21

标签: 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必须是静态的..)

1 个答案:

答案 0 :(得分:1)

put http:// on starting of your web address of your firefox driver. it is obligation in that selenium version.