Objective
File download time will pop up a download option box, this frame is not located, some elements are destined not to be able to locate it does not matter, when there is no mouse, we can use the keyboard shortcut keys to complete the operation.
SendKeys Library is a professional handling of keyboard events, so here need to use SendKeys to solve
First, download the scene
1. When you click the Download button, the following page pops up
2. If you want to click "Save File" button, solve the problem idea:
-First press TAB, move cursor focus to save button
-Press the ENTER key again, so that you can save the
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)
# Default on the Cancel button, first switch to save file
Sendkeys.sendkeys ("{tab}") # Send TAB key
Time.sleep (3)
# for the first time on Firefox, it didn't take effect, so you have to return
Sendkeys.sendkeys ("{ENTER}") # Send enter key
Sendkeys.sendkeys ("{ENTER}") # Send enter key
Selenium+python Automation 79-File Download (SendKeys) "Reprint"