簡體   English   中英

Java Selenium 如何“將圖像另存為”並按 Enter

[英]Java Selenium How to “save image as” and press Enter

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 然后按回車鍵保存圖像。

這是我的代碼:

 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);

當我執行此操作時,除了 PRESS ENTER 外,它可以正常工作,測試打開另存為 window 但仍保留在那里,無一例外,它只是無法按 ENTER 鍵。

有什么幫助嗎?

上下文菜單中的 Keys.ARROW_DOWN

通過context_click()啟動的上下文菜單通常在WebElement上調用,例如鏈接

@barancev [Selenium 的成員] 在他的評論中明確提到:

上下文單擊鏈接會打開無法由 Selenium 管理的本機上下文菜單(按設計)。


結論

使用Selenium您將無法使用send_keys(Keys.ARROW_DOWN)send_keys(Keys.DOWN)等與瀏覽器原生上下文菜單項進行交互。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM