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.