In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces python how to automate the test selenium operation drop-down list, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
To deal with the drop-down list, you need to use the utility class Select in selenium. The common methods are as follows:
Sample website: http://sahitest.com/demo
Example scenario: open the Sahi Tests page
(1) Click the "Select Test" page and click the first drop-down list on the page.
Sample script:
From selenium import webdriverfrom time import sleepfrom selenium.webdriver.support.select import Selectclass TestSelected (object): def setup (self): self.driver = webdriver.Chrome () self.driver.get ("https://sahitest.com/demo/") def test_selected (self): # dot" Select Test "link self.driver.find_element_by_xpath (" / html/body/table/tbody/tr/td [1] / A [4] "). Click () # Point the first drop-down box se=self.driver.find_element_by_id (" s1Id ") # Select the drop-down box option select=Select (se) # print the drop-down box option for options in select.options: print (options.text)
Running result:
(2) operate multiple selection list
Sample script:
From selenium import webdriverfrom time import sleepfrom selenium.webdriver.support.select import Selectclass TestSelected (object): def setup (self): self.driver = webdriver.Chrome () self.driver.get ("https://sahitest.com/demo/") def test_multiselected (self): # dot" Select Test "link self.driver.find_element_by_xpath (" / html/body/table/tbody/tr/td [1] / a [4] " ). Click () # list checkbox mulsel = self.driver.find_element_by_id ("s4Id") select2 = Select (mulsel) # Select all options in the list for i in range (6): select2.select_by_index (I) # reverse selection based on index value # select2.deselect_by_index (I) sleep (1) sleep (2) # invert all select2.deselect_all () self.driver.quit () Thank you for reading this article carefully I hope the article "python how to automate the test selenium operation drop-down list" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.