在Python中循环选择菜单硒

在Python中循环选择菜单硒,第1张

在Python中循环选择菜单硒

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

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

像这样:

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)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5667568.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存