Selenium Python firefoxwebdriver Processing Open Save dialog box

Source: Internet
Author: User
Tags selenium python

The code is as follows (online example):

< Span style= "COLOR: #008000" > #profile =  Webdriver. Firefoxprofile (r "C:\Users\Skyyj\AppData\Roaming\Mozilla\Firefox\Profiles\1rzh6139.default")
Profile = Webdriver. Firefoxprofile ()

# #设置成0代表下载到浏览器默认下载路径; set to 2 to save to the specified directory
profile.set_preference (" Browser.download.folderList ", 2)
#这里设置与否不影响, no effect was found.
#profile. Set_preference ("browser.download.manager.showWhenStarting", False)
Profile.set_preference (" Browser.download.dir ", R" C:\Down ")
Profile.set_preference (" Browser.helperApps.neverAsk.saveToDisk "," Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ")
#这里设置与否没有发现有什么影响
#profile. set_ Preference ("Browser.helperApps.alwaysAsk.force", False);
Self.driver = Webdriver. Firefox (Profile)

< Span style= "COLOR: #008000" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #800000" > < strong> self-written instance (environment:python3.6.5+selenium+pycharm+firefox61+firefoxdriver) :

< Span style= "COLOR: #008000" > < Span style= "COLOR: #000000" > < Span style= "COLOR: #000000" > from Selenium import Webdriver
from Selenium.webdriver.common.keys Import keys
Import time,os

profile = Webdriver. Firefoxprofile ()

#save the file to directory= < Span style= "COLOR: #000000" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #008000" >e:\sli\cifs2
Profile.set_preference ("Browser.download.dir", R "E:\sli\CIFS2")
Profile.set_preference ("Browser.download.folderList", 2)
Profile.set_preference ("browser.download.manager.showWhenStarting", False)

#download. zip file
Profile.set_preference ("Browser.helperApps.neverAsk.saveToDisk", "Application/zip")

#driver = Webdriver. Firefox (Firefox_profile=profile)
Driver = Webdriver. Firefox (Profile)

Driver.get ("http://10.49.5.8:8080/RLink/login.jsp")
Driver.maximize_window ()
#-----------------------------------Login Steps----------------------------------------------
# Input User Name
driver.find_element_by_id ("J_username"). Send_keys ("1")
Time.sleep (1)
# input Password
driver.find_element_by_id ("J_password"). Send_keys ("1")
Time.sleep (1)
# click "Log in" button
driver.find_element_by_id ("Buttonsubmit"). Click ()
Time.sleep (1)

#-----------------------------------Download Steps----------------------------------------------
# Highlight A zip file by XPath
Driver.find_element_by_xpath ("/html/body/div[6]/div[2]/div/div[7]/div/div/div[3]/div/div[4]/div/div[4]/div/div /div/div/div/ul/li[10]/div/table/tbody/tr[1]/td/div/div/div/table/tbody/tr/td/div/div/img "). Click ()
Time.sleep (2)
# click "Download" button
Driver.find_element_by_xpath ("/html/body/div[6]/div[2]/div/div[5]/div/table/tbody/tr/td[1]/table/tbody/tr/td[2 ]/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div "). Click ()
Time.sleep (2)

#-----------------------------------Logout Steps----------------------------------------------
# Click "Dropdown box" of User menu
Driver.find_element_by_xpath ('/html/body/div[6]/div[2]/div/div[5]/div/table/tbody/tr/td[2]/table/tbody/tr/td/ Div/table/tbody/tr/td[2]/table/tbody/tr/td[2]/img '). Click ()
Time.sleep (1)
# click "Log out"
Driver.find_element_by_xpath ("//div[text () = ' Log out ']"). Click ()
Time.sleep (1)
# click "Yes" on confirm Dialog
Driver.find_element_by_xpath ('/html/body/div[9]/div/div/div/div[3]/div/div[2]/button[1] '). Click ()
# click "No" on confirm Dialog
#driver. Find_element_by_xpath ('/html/body/div[9]/div/div/div/div[3]/div/div[2]/button[2] '). Click ()
Time.sleep (1)
Driver.quit ()

< Span style= "COLOR: #000000" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #008000" > 

Selenium Python firefoxwebdriver Processing Open Save dialog box

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.