Finding element while using Selenium Remote Server

214 views Asked by At

in my test I'm trying to download file from server, verify (if its downloaded) and delete it. But everytime I run my test with remote server (Selenium Grid, Chrome version=59.0.3071.115), I receive NullPointer during verification.

If I try run the test locally it passes without any problems.

My remote driver class

private WebDriver getRemoteDriver(Browser browser) throws MalformedURLException {
    DesiredCapabilities desiredCapabilities = getCapabilities(browser);
    desiredCapabilities.setCapability("platform", "LINUX");

    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    String downloadFilepath = System.getProperty("user.dir") + File.separator + "downloads";

    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadFilepath);
    chromePrefs.put("download.directory_upgrade", true);
    chromePrefs.put("download.extensions_to_open", "");
    chromePrefs.put("download.prompt_for_download", false);
    chromePrefs.put("plugins.always_open_pdf_externally", false);
    ChromeOptions options = new ChromeOptions();
    HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
    options.setExperimentalOption("prefs", chromePrefs);

    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
    desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);

    final RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(remoteUrl), desiredCapabilities);
    remoteWebDriver.setFileDetector(new LocalFileDetector());

    return new Augmenter().augment(remoteWebDriver);
}

And part of the test looks like this: Click button to download file, wait for new file and verify it, delete file.

driver.findElement(By.xpath(".//*[@id='browseOrders:browseView:browseViewPdfExpTblLnk']/span[1]"))
                .click();

    File file = navigationUtil.WaitForNewFile(download_folder, ".pdf", 60);

    String fname = file.getName();
    logger.info(fname);

    boolean success = file.exists();

    Assert.assertTrue(success);

    file.delete();

Im constantly getting java.lang.NullPointerException in line String fname = file.getName(); So I assume that the file is never downloaded.

Why there is a problem on remote server to find and click some elements. In this case there is menu that shows up after clicking "Gear button" and download button, but remote machine can't find the "Gear button" even when I try different ways to find it.

0

There are 0 answers