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

问题描述 投票:9回答:2

我试图用phantomjs无头浏览器运行selenium并得到“phantomjs://platform/console++.js:263 in error”错误消息。

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

相同的代码和解决方案不适合我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
selenium selenium-webdriver phantomjs headless-browser
2个回答
1
投票

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

 String[] phantomArgs = new String[] { "--webdriver-loglevel=NONE" }; 
 desireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
© www.soinside.com 2019 - 2024. All rights reserved.