Webdriver Advanced Apps-Right-click Save as Download file

Source: Internet
Author: User

1. To use the right-click Save, you need to first follow the third-party tool AutoIt:

Link: Https://pan.baidu.com/s/12aBBhOOTmyQpH9hukt0XGA Password: FCDK

2. Create a autoitscript editor named Loadfile.au3, which reads as follows:

Create a new Autoitscript editor named Loadfile.au3, with the following details:; Controlfocus ("title","text", ControlID); Indicates that the focus is switched to the ControlID in the title form; Edit1 represents the first instance that can be edited; title indicates the window title of the popup, and the title of the browser may be different controlfocus ("Please enter the file name you want to save ...","","Edit1"), wait 10 seconds for window windows to load successfully winwait ("[CLASS: #32770]","", 10), switch the focus to the Edit1 input box Controlfocus ("Save As","","Edit1"); Wait 2 seconds for sleep (2000the file name and path to be downloaded are written to the Edit1 edit box Controlsettext ("Save As","","Edit1","D:\iDownload\Firefox Setup 35.0b8.exe") Sleep (2000); Click the first button in the form, which is the Save button Controlclick ("Save As","","Button1"after saving, compile the file into an EXE file and store it on the local disk. 

3. After keeping the content, compile it into an EXE file and store it on the local disk.

Saved content can download files:

Link: Https://pan.baidu.com/s/13OWAiVMuSy_fW8PXTe_f5Q Password: ry4k

4. Write Python code for right-click saving:

#Encoding=utf-8 fromSeleniumImportWebdriverImportunittest, time, OS fromSelenium.webdriver.common.keysImportKeys fromSelenium.webdriverImportActionchainsImportWin32APIImportWin32convk_code={'Enter': 0x0D,'Down_arrow': 0x28}#Keyboard Key PressdefKeyDown (keyName): Win32api.keybd_event (Vk_code[keyname], 0, 0, 0)#keyboard keys lift updefkeyUp (keyName): Win32api.keybd_event (Vk_code[keyname], 0, Win32con. Keyeventf_keyup, 0)classTestdemo (unittest. TestCase):defsetUp (self):#self.driver = Webdriver. Ie (Executable_path = "E:\\iedriverserver")Self.driver = Webdriver. Chrome (executable_path="E:\\chromedriver")    defTest_datapickerbyrightkey (self):#define the URLs that will be visitedURL ="http://ftp.mozilla.org/pub/mozilla.org//firefox/releases/35.0b8/win32/zh-CN/"self.driver.get (URL)#Maximize the windowSelf.driver.maximize_window ()#pause for 5 seconds to prevent the page from having some extra pop-up window to occupy the focusTime.sleep (5)        #Find text content for "Firefox Setup 35.0b8.exe" hyperlink elementA = Self.driver.find_element_by_link_text ("Firefox Setup 35.0b8.exe") Time.sleep (2)        #simulate right-click on the link element found,        #to bring up a menu that selects the "Save as" optionactionchains (self.driver). Context_click (a). Perform ()#pause for 2 seconds to prevent command execution too fastTime.sleep (2)         forIinchRange (4):            #Loop Press the DOWN ARROW 4 times to switch focus to the Save As option            #different browsers may have different locations for this option            #A.send_keys (Keys.down)KeyDown ("Down_arrow") KeyUp ("Down_arrow")            PrintI time.sleep (2) Time.sleep (2)        #when the focus switches to the "Save as" option, simulate hitting enter        #bring up a Windows Form that saves the path to the download fileKeyDown ("Enter") KeyUp ("Enter") Time.sleep (3)        #save a form by executing a Windows file that AutoIt the action pop-up window        #to complete the file Save path settingsOs.system ("E:\API3\\upload_file1.exe")        #wait for the file download to complete, depending on the network bandwidth situation set to wait for the corresponding timeTime.sleep (5)    defTearDown (self): Self.driver.quit ()if __name__=='__main__': Unittest.main ()

Webdriver Advanced Apps-Right-click Save as Download file

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.