搜索不到网站的关键词,天津哪家公司做企业网站,个人简介网站源码,seo详细教程处理下拉列表需要使用selenium中的工具类Select#xff0c;常用方法如下#xff1a; 示例网站#xff1a;Sahi Tests
示例场景#xff1a;打开Sahi Tests页面#xff0c;
#xff08;1#xff09;点击“Select Test”页面#xff0c;鼠标点击页面中第一个下拉列表。 …处理下拉列表需要使用selenium中的工具类Select常用方法如下 示例网站Sahi Tests
示例场景打开Sahi Tests页面
1点击“Select Test”页面鼠标点击页面中第一个下拉列表。 示例脚本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 from selenium import webdriver from time import sleep from selenium.webdriver.support.select import Select class TestSelected(object): def setup(self): self.driver webdriver.Chrome() self.driver.get(https://sahitest.com/demo/) def test_selected(self): #点“Select Test”链接 self.driver.find_element_by_xpath(/html/body/table/tbody/tr/td[1]/a[4]).click() #点第一个下拉框 seself.driver.find_element_by_id(s1Id) #选中下拉框选项 selectSelect(se) #循环打印下拉框选项 for options in select.options: print(options.text)
运行结果 2操作多选列表 示例脚本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 from selenium import webdriver from time import sleep from selenium.webdriver.support.select import Select class TestSelected(object): def setup(self): self.driver webdriver.Chrome() self.driver.get(https://sahitest.com/demo/) def test_multiselected(self): #点“Select Test”链接 self.driver.find_element_by_xpath(/html/body/table/tbody/tr/td[1]/a[4]).click() #列表多选框 mulsel self.driver.find_element_by_id(s4Id) select2 Select(mulsel) #选择列表中所有选项 for i in range(6): select2.select_by_index(i) #根据索引值反选 # select2.deselect_by_index(i) sleep(1) sleep(2) #反选所有 select2.deselect_all() self.driver.quit()
现在我也找了很多测试的朋友做了一个分享技术的交流群共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源没人解答问题坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化性能安全测试开发等等方面有一定建树的技术大牛
分享他们的经验还会分享很多直播讲座和技术沙龙
可以免费学习划重点开源的
qq群号485187702【暗号csdn11】
最后感谢每一个认真阅读我文章的人看着粉丝一路的上涨和关注礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走 希望能帮助到你【100%无套路免费领取】