admin管理员组

文章数量:1391989

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!

本文标签: pythonSelenium driverwindowhandles suddenly taking too long to runStack Overflow