无法与PhantomJS和硒达到元素控制台

问题描述 投票:-1回答:1

我有一个代码,这个代码与镀铬驱动程序,但与幻象的js库1.4.4 2.1.1和司机不工作我不是能够找到的元素

此问题不会出现与chromedriver。

代码试验:

public void test1()
{
    DesiredCapabilities caps = new DesiredCapabilities();
    ((DesiredCapabilities) caps).setJavascriptEnabled(true);
    ((DesiredCapabilities) caps).setCapability("takesScreenshot",true);
    ((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/Users/santiagogalicia/downloads/phantomjs");
    caps.setJavascriptEnabled(true);
    String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
    WebDriver driver = new PhantomJSDriver(caps);
    Dimension dimension = new Dimension(400,600);
    driver.manage().window().setSize(dimension);
    driver.get("https://stage-commissionist.payclip.com/#/");
    WebDriverWait wait = new WebDriverWait(driver, 10);     
    wait.until(ExpectedConditions.elementToBeClickable(By.id("formUsername")));
    driver.findElement(By.id("formUsername")).sendKeys(User);
    driver.findElement(By.id("formPassword")).sendKeys(Password);
    driver.findElement(By.cssSelector(".btn")).click(); 
    driver.close();
}

我试图更改驱动程序,并与其他司机作品

,我看到的错误:

[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - msg: ReferenceError: Can't find variable: Set phantomjs://platform/console++.js:263 in error
[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - stack:
  (anonymous function) (https://stage-commissionist.payclip.com/static/js/1.ea7f0607.chunk.js:1)
  f (https://stage-commissionist.payclip.com/#/:1)
  phantomjs://platform/console++.js:263 in error
[ERROR - 2019-02-07T19:15:26.759Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1549566926721
java selenium-webdriver phantomjs headless headless-browser
1个回答
0
投票

正如你所提到的这个代码与镀铬驱动程序,但与幻象的js库1.4.4 2.1.1与此错误消息,...

[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - msg: ReferenceError: Can't find variable: Set phantomjs://platform/console++.js:263 in error
[ERROR - 2019-02-07T19:15:26.476Z] Session [b736bad0-2b0c-11e9-b0db-6d1517ea5006] - page.onError - stack: (anonymous function) (https://stage-commissionist.payclip.com/static/js/1.ea7f0607.chunk.js:1) f (https://stage-commissionist.payclip.com/#/:1)
phantomjs://platform/console++.js:263 in error [ERROR - 2019-02-07T19:15:26.759Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1549566926721

......意味着PhantomJSDriver未正确启动。

按照在ReferenceError: Can't find variable: Set主要原因的讨论似乎是以前版本的PhantomJS之一不支持ES2015 Set

您可以尝试uncss的实验分支,通过安装uncss-jsdom而是使用jsdom代替PhantomJS的。您可以在#265: Replace PhantomJS with jsdom合并。在这里,你可以找到关于Consider jsdom讨论

然而,随着硒v3.14.0和phantomjsdriver-1.4.4.jar代码块初始化PhantomJSDriver和鬼浏览器只是PERFECTO,您可以采用如下方案:

  • 代码块: package phantomJSDriver; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.phantomjs.PhantomJSDriverService; import org.openqa.selenium.remote.DesiredCapabilities; public class A_PhantomJS_DCap { public static void main(String[] args) { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setJavascriptEnabled(true); desiredCapabilities.setCapability("takesScreenshot", true); desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe"); String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"}; desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs); WebDriver driver = new PhantomJSDriver(desiredCapabilities); Dimension dimension = new Dimension(400,600); driver.manage().window().setSize(dimension); driver.get("https://www.google.co.in"); System.out.println(driver.getTitle()); driver.quit(); } }
  • 控制台输出: Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: executable: C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: port: 18249 Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: arguments: [--web-security=no, --ignore-ssl-errors=yes, --webdriver=18249, --webdriver-logfile=C:\Users\AtechM_03\LearnAutmation\learn-automation\phantomjsdriver.log] Feb 09, 2019 8:35:12 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: environment: {} [INFO - 2019-02-09T15:05:14.986Z] GhostDriver - Main - running on port 18249 [INFO - 2019-02-09T15:05:16.008Z] Session [1b791e00-2c7c-11e9-9e77-ef7d90721101] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":false} [INFO - 2019-02-09T15:05:16.008Z] Session [1b791e00-2c7c-11e9-9e77-ef7d90721101] - page.customHeaders: - {} [INFO - 2019-02-09T15:05:16.008Z] Session [1b791e00-2c7c-11e9-9e77-ef7d90721101] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-8-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 - 2019-02-09T15:05:16.008Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 1b791e00-2c7c-11e9-9e77-ef7d90721101 Feb 09, 2019 8:35:16 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Google [INFO - 2019-02-09T15:05:20.866Z] ShutdownReqHand - _handle - About to shutdown

注:根据您的评论的网站只能通过VPN提供,其私人网站,所以相关的代码与https://www.google.co.in测试

© www.soinside.com 2019 - 2024. All rights reserved.