Selenium python (12) Processing of drop-down boxes

Source: Internet
Author: User

#!/usr/bin/python
#-*-Coding:utf-8-*-
__author__ = ' Zuoanvip '

#下拉框在web页面上非常常见, the processing of the drop-down box uses a two-time positioning method for element positioning: First navigate to the drop-down box, and then locate the specific element of the drop-down box
From selenium import Webdriver
Import OS
Import time

Driver = Webdriver. Firefox ()
File_path = ' file:///' +os.path.abspath (' drop_down.html ')
Driver.get (File_path)

#首先定位到下拉框
Drop_down = driver.find_element_by_id (' ShippingMethod ')

# Click the drop-down box to the option
Drop_down.find_element_by_xpath ('//option[@value = ' 10.69 ') '. Click ()
Time.sleep (5)
Driver.quit ()

============================================

Drop_down.html Source

<body>
<select id= "ShippingMethod" onchange= "updateshipping (Options[selectedindex]);"
Name= "ShippingMethod" >
<option value= "12.51" >ups Next day Air ==> $12.51</option>
<option value= "11.61" >ups Next day Air Saver ==> $11.61</option>
<option value= "10.69" >ups 3 day Select ==> $10.69</option>
<option value= "9.03" >ups 2nd day Air ==> $9.03</option>
<option value= "8.34" >ups Ground ==> $8.34</option>
<option value= "9.25" >usps priority Mail Insured ==> $9.25</option>
<option value= "7.45" >usps priority Mail ==> $7.45</option>
<option value= "3.20" selected= "" >usps first Class ==> $3.20</option>
</select>
</body>

Selenium python (12) Processing of drop-down boxes

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.