Good day to all!

I am writing a self-test and ran into a problem.

Vovpros sounds briefly: How to upload files using Selenium?

Detailed: When you click on the link, apparently, the file itself must be downloaded. And I even set up a place to download files by default.

But I faced the fact that when you click on a link, PDF files are not downloaded, but opened in a new window. As a result, the download does not occur.

There is only one alternative in the head: Use requests library from Python

How would you upload a file in this situation? Please advise!

    2 answers 2

    I can not add a comment, unfortunately, so the answer is:

    Have you already tried the options offered in these questions?

    • Parameter to open pdf externally ("plugins.always_open_pdf_externally": True) from the second link is a cool option, it's interesting to try it yourself - Vic
    • @anasmi As a result, the answer from the first link helped me. Apparently your search skills are higher than mine :) Thank you very much! This answer helped here: stackoverflow.com/a/54427220/10684871 - Alan564

    Not that the solution to your problem, but as an option at least to speculate. Not so long ago I was looking for a way to switch to a new, open link page. Here is the option to switch to a new window that opens by clicking on the link:

    link.click() WebDriverWait wait = new WebDriverWait(getDriver(), 30); wait.until((WebDriver driver) -> driver.getWindowHandles().size() > 1); // ΠΆΠ΄Ρ‘ΠΌ Π½ΠΎΠ²ΡƒΡŽ Π²ΠΊΠ»Π°Π΄ΠΊΡƒ ArrayList<String> tabs2 = new ArrayList<>(getDriver().getWindowHandles()); // создаём список ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Ρ‹Ρ… Π²ΠΊΠ»Π°Π΄ΠΎΠΊ getDriver().switchTo().window(tabs2.get(1)); // Π’Ρ‹Π±ΠΎΡ€ Π²Ρ‚ΠΎΡ€ΠΎΠΉ Π²ΠΊΠ»Π°Π΄ΠΊΠΈ Π² качСствС Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΉ getDriver().findElement(By.xpath(".//body")).click(); // ΠΊΠ»ΠΈΠΊΠ°Π΅ΠΌ ΠΏΠΎ Π½ΠΎΠ²ΠΎΠΉ Π·Π°ΠΊΠ»Π°Π΄ΠΊΠ΅, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Ρ‚Π° стала Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΉ 

    Well, then you can already try to find a button to download. Good luck!