selenium + python循环用于动态下拉框

时间:2018-06-01 04:40:02

标签: python selenium

我有以下循环来浏览多个动态下拉框,将其提交到另一个网页,然后返回到初始页面以迭代所有选项。

问题是我需要插入一行以在每次循环之前将浏览器定向到初始页面。因此执行速度慢。有关改进代码的任何想法吗?

以下代码示例:

select = Select(driver.find_element_by_id('ID'))
options = select.options

for index in range(1, len(options):
   driver.get('webpage') # issue for slow execution speed
   select.select_by_index(index)
   select2 = Select(driver.find_element_by_id('ID2')) # can only select after selecting the first drop down box
   options2 = select2.options

   for index2 in range(1, len(options2):
     driver.get('webpage') # issue for slow execution speed
     select.select_by_index(index)
     select2 = Select(driver.find_element_by_id('ID2'))
     options2 = select2.options
     select2.select_by_index(index2)

     submit() # click on button to navigate to another page, read data then back to loop

0 个答案:

没有答案