您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Python中循环选择菜单硒

在Python中循环选择菜单硒

这应该为您工作。该代码

像这样:

from selenium import webdriver
from selenium.webdriver.support.ui import Select, webdriverwait
browser = 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 list

optionsList = []

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)
python 2022/1/1 18:35:02 有218人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶