In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.