Selenium+python Automation 79-File Download (SendKeys)

Source: Internet
Author: User
Tags save file

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 fromSeleniumImportWebdriverImportSendKeysImportTimedriver=Webdriver. Firefox () Driver.get ("Https://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe") Time.sleep (3)#by default on the Cancel button, first switch to save fileSendkeys.sendkeys ("{TAB}")#Send Tab keyTime.sleep (3)#The first time you enter the Firefox is not effective, so more than once returnSendkeys.sendkeys ("{ENTER}")#Send EnterSendkeys.sendkeys ("{ENTER}")#Send Enter

Selenium+python Automation 79-File Download (SendKeys)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.