-1

I have the next code, this code works with chrome driver but with phantom js 1.4.4 library and 2.1.1 driver is not working im not able to locate the elements

This issue doesnot appear with chrome driver.

Code trials:

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();
}

I tried change the driver and with other driver works

The error that I am seeing:

[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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [ask] page for help clarifying this question. – JeffC Feb 07 '19 at 17:43
  • @JeffC sorry i edit the problem – Santiago Galicia Feb 07 '19 at 17:50
  • Please check that the error message is complete. It looks like it's missing parts. On what line is this error? It looks like you have posted two unrelated error messages... one related to `Can't find variable: Set` and the other related to a timeout waiting for an element to be clickable. – JeffC Feb 07 '19 at 18:08
  • I can't reach the site listed. Are you sure the locator (id='formUsername') is good? Does the site load really slow? Maybe 10s isn't enough time? – JeffC Feb 07 '19 at 18:10
  • @JeffC i set the time to 20 seconds but the issue still, the locator its ok, its working with chromedriver – Santiago Galicia Feb 07 '19 at 19:18
  • @JeffC the site is only available by vpn, its a private site. – Santiago Galicia Feb 07 '19 at 19:47
  • Maybe switch it to wait for visible since you aren't clicking on it? You should post the relevant HTML in your question... maybe there's something we can see. – JeffC Feb 07 '19 at 19:47
  • this is the element and now i change the wait condition to wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("formUsername"))); – Santiago Galicia Feb 07 '19 at 22:27

1 Answers1

0

As you mentioned this code works with chrome driver but with phantom js 1.4.4 library and 2.1.1 this error message...

[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

...implies that the PhantomJSDriver wasn't initiated properly.

As per the discussion in ReferenceError: Can't find variable: Set main reason seems that one of the previous version of PhantomJS didn't support ES2015 Set.

Solution

You can try the experimental branch of uncss that uses jsdom instead of PhantomJS by installing uncss-jsdom instead. You can find the merge in #265: Replace PhantomJS with jsdom. Here you can find the discussion on Consider jsdom

However, with Selenium v3.14.0 and phantomjsdriver-1.4.4.jar your code block initializes PhantomJSDriver and Ghost Browser just perfecto and you can use the following solution:

  • Code Block:

    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();
        }
    }
    
  • Console Output:

    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
    

Note: As per your comment the site is only available by vpn, its a private site so the relevant code was tested with https://www.google.co.in

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • hi @DebanjanB, do you know how can i setup the jsdom to my eclipse project, i try with the code that you put, but this code works fine with phantomJS and eclipse. – Santiago Galicia Feb 11 '19 at 16:41
  • @SantiagoGalicia We haven't worked that extensively with jsdom but I have provided all the required documentation within my answer related to jsdom. – undetected Selenium Feb 11 '19 at 17:28