最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Selenium driver.window_handles suddenly taking too long to run - Stack Overflow

programmeradmin2浏览0评论

I have a webscrapping script using selenium that goes into a website, do some things, and then clicks on multiple download links. Browser being used is Edge.

Uppon clicking on the download link another blank window opens just to download a file to the C:/Download dir. I do time.sleep(5), switch to that new window, close it, go back to the main window and click the next download link, repeat. Like this:

 def download_page(driver):
    download_buttons = driver.find_elements(By.XPATH, "//span[@id='btnDownload']/a")
    for button in download_buttons:    
        print(button)
        # Move para o botão e clica
        ActionChains(driver).move_to_element(button).click(button).perform()
        driver.switch_to.window(driver.window_handles[-1])
        time.sleep(5)
        driver.close()    
        driver.switch_to.window(driver.window_handles[0])

This script ran pretty fast for weeks until yesterday. Now, when I run the line driver.window_handles, it takes more than 10 minutes to get the results.

This only happens after the download link is clicked and the new blank window is opened. If I run the driver.window_handles command while only having the main window open, it works fine.

I don't get any errors; it just takes forever to run. Any ideas on what could cause this behavior?

I'm also open to workaround suggestions. I'm considering using a mouse automation script to solve it quickly, but that is not ideal since it would require that no one uses the computer while the script runs, which is possible but annoying.

Thanks for your attention!

发布评论

评论列表(0)

  1. 暂无评论