Selenium Webdriver Study notes (iii)

Source: Internet
Author: User

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)

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.