栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Python中循环选择菜单selenium

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Python中循环选择菜单selenium

这应该为您工作。该代码将

  • 查找元素
  • 迭代以从下拉列表中获取所有选项
  • 遍历列表
  • 对于列表中的每个项目,选择当前选项
  • 由于网页已更改,因此必须在每次通过时重新选择下拉菜单

像这样:

from selenium import webdriverfrom selenium.webdriver.support.ui import Select, WebDriverWaitbrowser = webdriver.Firefox()browser.get("http://www.website.com")select = browser.find_element_by_xpath( "//select[@id='idname']")  #get the select element options = select.find_elements_by_tag_name("option") #get all the options into a listoptionsList = []for option in options: #iterate over the options, place attribute value in list    optionsList.append(option.get_attribute("value"))for optionValue in optionsList:    print "starting loop on option %s" % optionValue    select = Select(browser.find_element_by_xpath( "//select[@id='idname']"))    select.select_by_value(optionValue)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401420.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号