foreword
When the file is downloaded, a download option box will pop up. This pop-up box cannot be located. It does not matter if some elements are destined to be located. If there is no mouse, we can complete the operation through the keyboard shortcuts.
The SendKeys library is specialized in handling keyboard events, so it needs to be solved with SendKeys
1. Download the scene
1. When the download button is clicked, the following page will pop up
2. If you want to click the "Save File" button to solve the problem:
- Press the TAB key first, move the cursor to focus on the save button
- Press ENTER again to save
Second, the code implementation
# coding:utf-8 from selenium import webdriver import SendKeys import time driver = webdriver.Firefox() driver.get("https://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe") time.sleep( 3 ) #The default is on the cancel button, first switch to the save file SendKeys.SendKeys( " {TAB} " ) #Send the TAB key time.sleep( 3 ) #The first carriage return on Firefox did not take effect, So send the carriage return once more SendKeys.SendKeys( " {ENTER} " ) #Send the carriage return key SendKeys.SendKeys( " {ENTER} " ) #Send carriage return key