Selenium java + PhantomJS - phantomjs://platform/console++.js:263错误

时间:2016-11-15 01:00:04

标签: selenium selenium-webdriver phantomjs headless-browser

我试图使用phantomjs无头浏览器运行selenium并获取错误" phantomjs://platform/console++.js:263错误"错误信息。

通过互联网搜索但没有得到任何解决方案,所以问这里。

相同的代码和解决方案对我不起作用Link

为什么我收到此错误消息?,这是phantomjs问题还是selenium?让我知道如何解决它?。

配置:

1)Selenium 2.53.1.jar

2)Phantomjs 2.1.1 .exe

3)Junit4

代码:

private PhantomJSDriver driver;
    private String baseUrl;

    @Before
    public void setUp() throws Exception {
       // File file = new File("D:/Selenium/Drivers/phantomjs.exe");
       // System.setProperty("phantomjs.binary.path", file.getAbsolutePath());

        System.setProperty("phantomjs.binary.path", "D:/Selenium/Drivers/phantomjs.exe");
        Capabilities caps = new DesiredCapabilities();
        ((DesiredCapabilities) caps).setJavascriptEnabled(true);                
        ((DesiredCapabilities) caps).setCapability("takesScreenshot", true);  
        //((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "D:/Selenium/Drivers/phantomjs.exe");
        WebDriver   driver = new  PhantomJSDriver(caps);

        driver = new PhantomJSDriver();
        baseUrl = "http://www.gts.fiorentina.test/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get(baseUrl + "/Account/Login.aspx?ReturnUrl=%2f");

        driver.findElement(By.id("tbUserName_I")).clear();
        driver.findElement(By.id("tbUserName_I")).sendKeys("rogai");
        driver.findElement(By.id("tbPassword_I")).clear();
        driver.findElement(By.id("tbPassword_I")).sendKeys("Fiorentina2014!");
        driver.findElement(By.id("btnLogin_CD")).click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testCreazione() throws Exception {
        driver.get(baseUrl + "/SegreteriaSportiva/Calciatori.aspx");

        driver.findElement(By.cssSelector("#ASPxButton1_CD > span")).click();

        driver.findElement(By.id("FrmEdit_TS_TipoPersonaId_FK_B-1")).click();
        driver.findElement(By.id("FrmEdit_TS_TipoPersonaId_FK_DDD_L_LBI2T0")).click();
        driver.findElement(By.id("FrmEdit_Nome_I")).clear();
        driver.findElement(By.id("FrmEdit_Nome_I")).sendKeys("Prova");
        driver.findElement(By.id("FrmEdit_Cognome_I")).clear();
        driver.findElement(By.id("FrmEdit_Cognome_I")).sendKeys("Calciatore");
        driver.findElement(By.id("FrmEdit_TS_RuoloId_FK_B-1")).click();
        driver.findElement(By.id("FrmEdit_TS_RuoloId_FK_DDD_L_LBI3T0")).click();
        driver.findElement(By.id("FrmEdit_DataNascita_I")).clear();
        driver.findElement(By.id("FrmEdit_DataNascita_I")).sendKeys("01/01/2014");
        driver.findElement(By.id("FrmEdit_Cittadinanza_I")).clear();
        driver.findElement(By.id("FrmEdit_Cittadinanza_I")).sendKeys("italiana");
        driver.findElement(By.id("FrmEdit_LuogoNascita_I")).clear();
        driver.findElement(By.id("FrmEdit_LuogoNascita_I")).sendKeys("roma");
        driver.findElement(By.cssSelector("#BTN_Edit_CD > span")).click();
        driver.findElement(By.id("Grid_DXFREditorcol3_I")).click();
        driver.findElement(By.id("Grid_DXFREditorcol3_I")).sendKeys("Prova");
}

错误讯息:

    INFO: environment: {}
[INFO  - 2016-11-15T00:41:42.115Z] GhostDriver - Main - running on port 20668
[INFO  - 2016-11-15T00:41:42.955Z] Session [4766f980-aacc-11e6-a7fd-efd8c5848edd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2016-11-15T00:41:42.955Z] Session [4766f980-aacc-11e6-a7fd-efd8c5848edd] - page.customHeaders:  - {}
[INFO  - 2016-11-15T00:41:42.956Z] Session [4766f980-aacc-11e6-a7fd-efd8c5848edd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-7-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2016-11-15T00:41:42.956Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 4766f980-aacc-11e6-a7fd-efd8c5848edd
[ERROR - 2016-11-15T00:42:27.341Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1479170547300

  phantomjs://platform/console++.js:263 in error

2 个答案:

答案 0 :(得分:1)

只需设置驱动程序功能即可将Web驱动程序日志级别设置为NONE。日志不会显示。

 String[] phantomArgs = new String[] { "--webdriver-loglevel=NONE" }; 
 desireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);

答案 1 :(得分:-1)

不再使用PhantomJS。

It's no longer supportedno longer in development和Github has been archived上的代码。

现在可以使用ChomeDriver in headless modeGeckoDriver in headless mode代替PhantomJS。