无法使用selenium webdriver启动任何浏览器

时间:2017-05-31 09:27:46

标签: eclipse firefox selenium-webdriver

我正在尝试使用eclipse运行Selenium网络驱动程序自动化但无法打开浏览器窗口。调试日志显示没有错误,我成功地能够检索网页的标题,如下所示:

try {
        System.setProperty("webdriver.gecko.driver","/Users/shankar.sharma/Downloads/chrome-driver/geckodriver");

        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);

        FirefoxOptions options = new FirefoxOptions();
        options.addPreference("log", "{level: error}");

        WebDriver driver = new FirefoxDriver();
        driver.navigate().to("http://www.seleniumhq.org/download/");
        String appTitle = driver.getTitle();
        System.out.println("Application title is :: "+appTitle);
        driver.quit();
    } catch (Exception e) {
        System.out.println("Exception:"+e.getMessage());
    }

调试日志: 1496221115902 geckodriver INFO在127.0.0.1:39119上收听 1496221116097 geckodriver :: marionette INFO使用args启动浏览器/Applications/Firefox.app/Contents/MacOS/firefox-bin [" -marionette"] 1496221117678 Marionette INFO在端口63210上收听 2017年5月31日下午2:28:38 org.openqa.selenium.remote.ProtocolHandshake createSession 信息:检测到的方言:W3C 2017-05-31 14:28:38.036 plugin-container [55325:3295542] * CFMessagePort:bootstrap_register():失败1100(0x44c)'权限被拒绝',port = 0x9c3b,name =& #39; com.apple.tsm.portname' 有关错误代码,请参阅/usr/include/servers/bootstrap_defs.h。 2017-05-31 14:28:38.038 plugin-container [55325:3295542] * CFMessagePort:bootstrap_register():失败1100(0x44c)'权限被拒绝',port = 0x9f03,name = ' com.apple.CFPasteboardClient' 有关错误代码,请参阅/usr/include/servers/bootstrap_defs.h。 应用程序名称是:: Downloads 1496221129876 Marionette INFO将不再接受新的连接

但是浏览器窗口没有打开。我也尝试过使用chrome驱动程序,但这也无法正常工作。我使用以下配置:

  • Selenium Web-driver:3.4.0
  • LGecko驱动程序:v0.16.0

关于导致这种情况发生的原因的任何想法?

2 个答案:

答案 0 :(得分:1)

我已经在我的Mac中检查了相同但它对我来说工作正常..以下是我可以看到浏览器已自动启动的默认代码...

 public static void main(String[] args) 
{ 
   System.setProperty("webdriver.chrome.driver", "/Users/santhoshkumar/Documents/Softwares/chromedriver"); 
   driver.manage().windows().maximize();
   WebDriver driver = new ChromeDriver(); 
   driver.get("http://facebook.com"); 
   System.out.println(driver.getTitle()); 
}

因为这不适合你..尝试使用chromeoptions ..

public static void main(String[] args) 
{ 
  System.setProperty("webdriver.chrome.driver", "/Users/santhoshkumar/Documents/Softwares/chromedriver"); 
  ChromeOptions options = new ChromeOptions(); 
  options.addArguments("start-maximized"); 
  options.addArguments("--start-fullscreen");
  WebDriver driver = new ChromeDriver(options); 
  driver.get("http://facebook.com"); 
  System.out.println(driver.getTitle()); 
}

希望这会对你有所帮助。谢谢。

答案 1 :(得分:0)

this链接上查看我的回答,确保您的浏览器firefox version低于48.0
享受:)

相关问题