The operation check box Selenium

Check the box operation:

      The so-called check box, which means you can check one or more or all of the check. Check the box icons are generally square.

Check the check box is generally divided into three cases:

     ① check a single box, the way we use elements directly-targeted to click away.

     ② check multiple boxes, we wanted to check a few, you navigate to a few, and finally click away.

     ③ all checked, the checkbox to obtain all the objects, and then take a click-through for loop.

The following code is attached cb.html screenshot:

     

 

Selenium is achieved by the code:

 

import time

from selenium import webdriver

# Designated driver

driver = webdriver.Chrome(r"C:\webdriver\chromedriver.exe")

# Open URL

driver.get('file:///C:/Users\Administrator/PycharmProjects/1120/web_driver/lesson3/cb.html')

input1 = driver.find_element_by_css_selector('input[value=car]')

To determine whether you have selected #

selected = input1.is_selected()

if selected:

      print ( 'has been selected')

else:

      print ( 'unselected')

      input1.click()

 

time.sleep(2)

driver.quit()

Guess you like

Origin www.cnblogs.com/peipei-Study/p/11883751.html