import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Webdriver {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");
//WebDriver driver = new ChromeDriver();
driver.get("https://maps.mapmyindia.com");
Thread.sleep(2000);
driver.findElement(By.id("auto")).sendKeys("TCS");
Thread.sleep(2000);
driver.findElement(By.id("auto_geo")).click();
当我在eclipse luna上运行此代码时出现错误:线程“main”中的异常org.openqa.selenium.SessionNotCreatedException:无法找到匹配的一组功能
new FirefoxDriver(DesiredCapabilities caps);
已弃用,请使用
FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette", false);
WebDriver webDriver = new FirefoxDriver(options);
你很高兴
你应该为firefox添加功能。请修改您的代码如下
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("https://maps.mapmyindia.com");
如果你的窗户是windows_nt
然后把windows_nt
而不是windows
SessionNotCreatedException
扩展WebDriverException
并且是RuntimeException
,表示无法创建会话。
无法创建新会话的可能原因如下:
JDK
,Selenium
,WebDriver
和Web Browser
版本之间的兼容性问题。GeckoDriver
或Marionette
通过之前会话尚未发布的新会话访问相同的端口号。CPU
Physical Memory
Swap Memory
Disc Cache
Network Bandwidth
OS chores
。我没有在您的代码块中看到任何编码问题。
简单的解决方案如下:
另一个可能的原因是过时的Firefox版本。
我升级了版本,它工作正常!
我只能打开浏览器设置options.setCapability("marionette", true);
,然后在打开的窗口中我通过“关于Firefox”对话框升级。然后你必须删除关于marionette
的行。
可能我所拥有的只是与marionette
合作,而我们正试图将它与geckodriver
一起使用,qazxswpoi有不同的协议。任何比我更了解的人都可以确认或否认!