Selenium+python Automation 79-File Download (SendKeys) "Reprint"

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
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"

Related Article

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.