gpt4 book ai didi

Python Selenium - 等到表单提交后加载下一页

转载 作者:太空狗 更新时间:2023-10-29 21:23:36 25 4
gpt4 key购买 nike

我正在使用 Python3 和 Selenium firefox 提交表单,然后获取他们登陆的 URL。我是这样做的

inputElement.send_keys(postnumber)
inputElement.submit()

time.sleep(5)

# Get Current URL
current_url = driver.current_url
print ( " URL : %s" % current_url )

这在大部分时间都有效,但有时页面加载时间超过 5 秒,我得到旧 URL,因为新 URL 尚未加载。

我应该怎么做?

最佳答案

expected_conditions 中的

url_changes 助手就是为了这个目的:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# some work on current page, code omitted

# save current page url
current_url = driver.current_url

# initiate page transition, e.g.:
input_element.send_keys(post_number)
input_element.submit()

# wait for URL to change with 15 seconds timeout
WebDriverWait(driver, 15).until(EC.url_changes(current_url))

# print new URL
new_url = driver.current_url
print(new_url)

关于Python Selenium - 等到表单提交后加载下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com