0

I'm trying to achieve the following : I have the following url : https://img.pokemondb.net/sprites/sword-shield/icon/bulbasaur.png I need to press ctrl + s via Selenium to open the download Windows window and then press enter in order to save the image.

This is my code :

 WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();

    Robot robot = new Robot();

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    
    String url = "https://img.pokemondb.net/sprites/sword-shield/icon/bulbasaur.png";
    driver.get(url);

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_S);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_S);
    robot.delay(1000);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);

When I execute this , it works everything EXCEPT the PRESS ENTER , the test open the save as window but remain there , without any exception , it just cannot press ENTER key .

Any help ?

luator
  • 4,769
  • 3
  • 30
  • 51
Nexussim Lements
  • 535
  • 1
  • 15
  • 47

1 Answers1

0

Keys.ARROW_DOWN within Context Menu

Context Menu initiated through context_click() is generally invoked on a WebElement e.g. a link.

@barancev [Member of Selenium] in his comment clearly mentions:

contextClick on a link opens a native context menu that can't be managed by Selenium (by design).


Conclusion

Using Selenium you won't be able to interact with browser native context menu items using send_keys(Keys.ARROW_DOWN), send_keys(Keys.DOWN), etc.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352