This section focuses on:
Uploading files
File upload operation is also one of the most common functions, upload function is not used to new methods or functions, the key is thinking.
The upload process typically opens a local window and selects the local file to add from the window. So, generally will card in how to operate the local window to add upload files.
In fact, in selenium webdriver not so complicated as we think; just locate the upload button and Send_keys add the local file path to it. Absolute path and relative path are all OK, the key is to upload the file exists. The following is an example demo.
Upload_file.html
upload.py
#coding =utf-8 from
Selenium import webdriver
import os,time
driver = webdriver. Firefox ()
#脚本要与upload_file. HTML same directory
File_path = ' file:///' + os.path.abspath (' upload_file.html ')
Driver.get (File_path)
#定位上传按钮, add local file
driver.find_element_by_name ("file"). Send_keys (' D:\\selenium_use_ Case\upload_file.txt ')
time.sleep (2)
driver.quit ()
Other applications are not easy to find, so just create your own pages, which is troublesome, but the scripting code highlights the focus.
Here to find 1139 instances of mailboxes, have an account of the students can test the ~!
(landing basic version of the 139 mailbox, network disk module upload file.) )
139upload.py
#coding =utf-8 from
Selenium import webdriver
import os,time
driver = webdriver. Firefox ()
driver.get ("http://m.mail.10086.cn")
driver.implicitly_wait
#登陆
driver.find_ element_by_id ("ur"). Send_keys ("mobile number")
driver.find_element_by_id ("PW"). Send_keys ("password")
Driver.find_ Element_by_class_name ("Loading_btn"). Click ()
time.sleep (3)
#进入139网盘模块
driver.find_element_by_ XPath ("/html/body/div[3]/a[9]/span[2]"). Click ()
time.sleep (3)
#上传文件
driver.find_element_by_id (" Id_file "). Send_keys (' d:\\selenium_use_case\upload_file.txt ')
time.sleep (5)
driver.quit ()
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/