#!/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