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

前端 未结 2 1147
忘了有多久
忘了有多久 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:11

    To select all the elements from multiple e.g. two (2) different drop-down-select elements within the website https://price.joinsland.joins.com/theme/index_theme.asp?sisaegbn=T05 you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following xpath based Locator Strategies:

    driver.get('https://price.joinsland.joins.com/theme/index_theme.asp?sisaegbn=T05')
    select1 = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@name='sido']"))))
    for item1 in select1.options:
        item1.click()
        select2 = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@name='gugun']"))))
        for item2 in select2.options:
            item2.click()
            time.sleep(3) # perform your web-crawling here
    

提交回复
热议问题