StaleElementReferenceException: element is not attached to the page document while selecting the options from multiple Dropdowns using Selenium Python

前端 未结 2 1172
忘了有多久
忘了有多久 2021-01-26 14:34

Code trial:

#coding=utf-8

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from seleni         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-26 15:29

    This is what I figured out. But I'm not sure if code is right or not. I don't know python.

    #get select
    select1 = Select(driver.find_element_by_xpath('//select[@name="sido"]'))
    
    #get all options from select
    options1 = select1.options
    
    for opt1 is options1:
    
        #select the option which has the value of opt1
        select1.select_by_value(opt1.get_attribute("value"))
        time.sleep(5)
    
        select2 = Select(driver.find_element_by_xpath('//select[@name="gugu"]'))
        options2 = select2.options
    
        for opt2 in options2:
            select1.select_by_value(opt2.get_attribute("value"))
            time.sleep(4)
    

提交回复
热议问题