我正在尝试在 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/