0

My goal is to download .jnlp file which is considered as a harmful file by chrome.

So, i have thought 2-3 solutions for this. I am using Chrome 76 version and i dont want to downgrade the chrome version.

1st solution:

Download JNLP file it will give warning and then go to download page and then click Tab 4-5 times to reach to Keep button and then hit enter using Keys.ENTER but it is visible that it hits the Keep button but it is not doing anything as if it is not clicked.

2nd solution:

Download JNLP file it will give warning and then go to download page and then click on Keep button using the xpath. So, i have already figured it out that in Downloads page it is having Shadow dom so i reach to the page-button tag but it is saying xpath is not valid.

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //[@id='dangerous']/paper-button[2]) because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//[@id='dangerous']/paper-button[2])' is not a valid XPath expression.

3rd solution: Open the dialogue box for saving and then click okay to download somewhere else so that warning message will not come. But dialouge box is not getting opened.

Code for option 2:

      WebElement root1 = cd.findElement(By.tagName("downloads-manager"));
      WebElement shadowRoot1 = GetRootElement(root1);

      WebElement root2 = shadowRoot1.findElement(By.id("downloadsList"));
      // WebElement shadowRoot2 = GetRootElement(root2);

      WebElement root3 = root2.findElement(By.cssSelector("downloads-item"));
      WebElement shadowRoot3 = GetRootElement(root3);

      shadowRoot3.findElement(By.xpath("//*[contains(@id,'dangerous')]//paper-button[2]")).click();

      public WebElement GetRootElement(WebElement element) {

            WebElement ele = (WebElement) ((JavascriptExecutor) cd).executeScript("return arguments[0].shadowRoot", element);

    return ele;

  }

Error i got: Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //[@id='dangerous']/paper-button[2]) because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//[@id='dangerous']/paper-button[2])' is not a valid XPath expression.

  • Why not skip Chrome and start it via command line e.g.: "javaws foo.com/test_app.jnlp" – Prome Oct 1 at 10:45
  • Requirement is doing it by using Chrome. – Ranjit Singh Saluja Oct 1 at 10:57
  • What is the risk that a Chrome agent covers that a simple cURL would not? – João Farias Oct 1 at 11:26
  • Requirement is to test the dialogue or just to start the app and then perform tests? You can disable Safe browsing feature in Chrome and you will not get those pop-ups. – Prome Oct 1 at 11:26
  • 1
    I meant (your) product risk. You said that downloading the file through Chrome and through javaws cover different risks. The question about what is the specific reason for using Chrome may uncover another approach that can be equivalent to using Chrome. – João Farias Oct 4 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.