the webdriver (d) ----- positioning radio frame, checkbox box, select the frame with the operating

Radio frame positioning and operation, checkbox block, select box

radio box

radio box to select options directly click method WebElement to simulate the user clicks on it

Gives the following html

<div id="radio">
  <input type="radio" name="zimu" value="a">a<br>
  <input type="radio" name="zimu" value="b">b<br>
  <input type="radio" name="zimu" value="c" checked="checked">c
</div>

If we want to print the value of the current default radio button selected

# Get the currently selected element 
Element = wd.find_element_by_css_selector (
   ' #radio INPUT [= the checked the checked] ' )
 Print ( ' is currently selected: ' + element.get_attribute ( ' value ' ))

If we are to choose web automation options for a value of

# 选择a
wd.find_element_by_css_selector(
  '#radio input[value="a"]').click()

 

checkbox box

<div id="html">
  <input type="checkbox" name="zimu" value="a">a<br>
  <input type="checkbox" name="zimu" value="b">b<br>
  <input type="checkbox" name="zimu" value="c">c
</div>

 

We have to choose ab two boxes:

wd.find_element_by_css_selector(
  "#checkbox input[value='a']").click()
wd.find_element_by_css_selector(
  "#checkbox input[value='b']").click()

 

select frame

and select a radio sub-multiple choice, select for, the Selenium provides a dedicated Select 类对其 operation.

Select class provides the following methods as follows

select_by_value: According to value the options 属性值 , select elements.

select_by_visible_text: according to the text options, select elements

select_by_value: remove the selected element based on property value of the option value

select_by_visible_text: According to the visible text options

sselect_deselect_all():去除选中的元素

<select id="dsing">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

We choose saab an example

# Import Select class 
from selenium.webdriver.support.ui Import Select
 from Selenium Import the webdriver 
WD = webdriver.Chrome (R & lt ' D: \ Automation the Web \ chromedriver.exe ' )
 # Create Object Select 
S = Select (wd.find_element_by_id ( " dsing " )) 

# selected by the select object Saab 
s.select_by_visible_text ( " Saab " ) 

# selected by Saab value value select object 
s.select_by_value ( " Saab " )

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/xxxyang/p/11833479.html
Recommended