Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use checkbox and radiobox Technology of selenium Operation in python

Shulou Source: shulou.com Published: 2022-06-02 15:23:47 10月04日 Update

This article introduces the relevant knowledge of "how to use checkbox and radiobox technology of selenium operation in python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Check boxes (checkbox) and radiobox are often involved in form forms. Check boxes can be used for users' hobbies such as running, swimming and dancing, and check boxes can be used for men and women of both sexes.

(1) checkbox selection or reverse selection: use the click () method

(2) radiobox has the same name and multiple values, which can be obtained first by name, and then judged by value, choose to use click () method.

Page code:

Title tests from form operations checkbox and radiobutton

Running:

Swimming:

Dance:

Gender:

Male:

Female:

Sample script:

Import os from selenium import webdriverfrom time import sleep class TestCheckBoxOrRadioBtn (object): def setup (self): self.driver = webdriver.Chrome () path = os.path.dirname (os.path.abspath (_ _ file__)) file_path = 'file:///'+path+'/html/form.html' self.driver.get (file_path) def test_checkbox (self): # position Dance Dancing=self.driver.find_element_by_name ("dancing") # if there is no choice Click to select if not dancing.is_selected (): dancing.click () sleep (2) running = self.driver.find_element_by_name ("running") if not running.is_selected (): running.click () sleep (2) swimming = self.driver.find_element_by_name ("swimming") If not swimming.is_selected (): swimming.click () sleep (2) # Click again to deselect swimming swimming.click () sleep (2) self.driver.quit () def test_radio (self): # to get the element list gender= self.driver.find_elements_by_name ("gender") # Select male gender [0] .click () sleep (2) # Select female gender [1] .click () sleep (2) self.driver.quit () if _ _ name__ = ='_ main__': case = TestCheckBoxOrRadioBtn () case.test_checkbox () case.test_radio ()

Running result:

This is the end of the content of "how to use checkbox and radiobox technologies operated by selenium in python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Selection gender swimming technology content name method more knowledge forms check boxes practical identical successful learning next code elements again boundaries dilemma Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft vpn Shulou Technology OPPO Reno