Selenium Webdriver
One, upload file operation
To upload a folder you typically open a local window and select a local file from the window to add. So the general will be stuck in how to operate the local window to add upload files.
In fact, the selenium webdriver is not as complicated as we thought. Just navigate to the upload button and add a local file via Send_keys path. Absolute path and relative path are all possible, the key is the upload file exists.
Example:
From selenium import Webdriver
Import Os,time
#脚本要与测试html同一目录
File_path = ' file:///' + os.path.abspath (' upload_file.html ')
Driver.get (File_path)
#定位到上传按钮, add a local file
Driver.find.element_by_name ("file"). Send_keys (' D:\upload_file.txt ')
Time.sleep (2)
Driver.quit ()
Second, drop-down box processing
The drop-down box is one of our most common page elements, and for general elements, we only need to locate them once. The contents of the drop-down box need to be positioned two times, navigate to the bottom bar, and then locate the options in the drop-down box.
1. Operation Drop-down box example
#先定位置到下拉框
m = browser.find_element_by_id ("City")
#再点击下拉框下的选项
M.find_element_by_xpath ("* * *"). Click ()
Time.sleep (2)
Browser.quit ()
Selenium Webdriver Study notes (iii)