single python selenium / operation box

First, radio: Radio

  1. The first positioning location selection box

 

  2. Locate id, click on the icon on it, the following code (url address acquisition method: Paste the above source code to save text as .html suffix browser open, copy the url address in the browser address bar on it)

  3. Click the first boy, such as ten seconds and then click on the observed change girl page

 

Second, check boxes: the CheckBox

  1. Select a single frame, such as selenium this check, it can directly target id = c1 clicks on it

 

 

 

 

   2. So the question is: If you want to check on all of it?

Third, all of the check:

    1. Check all, can be used to locate a set of elements, the source can be seen from the above, a check box type = checkbox, can be used here xpath Syntax: .//* [@ type = 'checkbox']

 

     2. Note that here, the knock blackboard notes: find_elements is not directly clicked, it is complex, it must first of all get to the checkbox object, and then cycle to a click-through operation for

Fourth, determine whether selected: is_selected ()

    1. Sometimes this box itself is selected, and if I click, it unselected, this is not the result I expected, so can you if it is not selected, I went to click on the next; when it has been selected, I will not click on it? So the question arises: how to determine the option box is checked?

    2. determine whether the element is selected core of this step is the article, click the check box for all of us no difficulty. Gets whether the element is selected, the print results as shown below.

    3. Return the result of type bool, did not click when returns False, click returns True, the next it is easy to judge, either as a judge before the operation, can be used as the test results to determine

 

Seven, reference code:

# coding:utf-8

from selenium import webdriver

driver = webdriver.Firefox()

driver.get("file:///C:/Users/Gloria/Desktop/checkbox.html")

# 没点击操作前,判断选项框状态

s = driver.find_element_by_id("boy").is_selected()

print s

driver.find_element_by_id("boy").click()

# 点击后,判断元素是否为选中状态

r = driver.find_element_by_id("boy").is_selected()

print r

 

# 复选框单选

driver.find_element_by_id("c1").click()

# 复选框全选

checkboxs = driver.find_elements_by_xpath(".//*[@type='checkbox']")

for i in checkboxs:

    i.click()

 

Guess you like

Origin www.cnblogs.com/Mr-ZY/p/11696658.html