Selenium Python 提交()错误:陈旧元素引用异常

问题描述 投票:0回答:1

a=webdriver.Chrome()

a.get(“C:/Users/html_code_03_02.html”)

select1=a.find_element(By.NAME,"numReturnSelect")

选项2=选择(选择1)

对于范围内的 i(len(option2.options)):

option2.select_by_index(i)
time.sleep(2)
submit1 = a.find_element(By.NAME, "continue")
print(submit1)
submit1.submit()

a.close()

它进入 for 循环,之后选择索引,但一旦到达 Submit1,它就会失败

每次它都应该迭代每个索引的循环,并且应该单击提交,但这没有发生

python selenium-webdriver automated-tests
1个回答
0
投票

您尝试过吗

WebDriverWait
,我想这会解决您的问题。

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_argument("start-maximized")
a = webdriver.Chrome(options=chrome_options)
a.get("C:/Users/html_code_03_02.html")

select1 = a.find_element(By.NAME,"numReturnSelect")
option2 = Select(select1)

for i in range(len(option2.options)):
    option2.select_by_index(i)
    WebDriverWait(a, 20).until(EC.element_to_be_clickable((By.NAME, "continue")))
    submit1 = a.find_element(By.NAME, "continue")
    print(submit1)
    submit1.submit()

a.close()
© www.soinside.com 2019 - 2024. All rights reserved.