Selenium, не записывает html страницу в файл

Проблема в том, что файл, который создаётся при попытке сохранить html, пустой, хотя переменная new_page, если её вывести, не пустая. Мой код:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time

class class_parser():
   
    def main_parser(url, chrome):
        driver = webdriver.Chrome(chrome) 
        try:
            go_to_url = driver.get(url)
            time.sleep(3)
            while True:

                find_elem = driver.find_element_by_xpath("//div[@class='ec-footer']")

                if driver.find_elements_by_xpath("//a[@class='ec-footer__link ec-link ec-link--muted link--icon-top footer__link--shopping-cart footer__link--empty']"):
                    new_page = driver.page_source
                    with open("index.html", "w") as file:
                        file.write(new_page)
                        
                        break
                else:
                    action = ActionChains(driver)
                    action.move_to_element(find_elem).perform()

        except Exception as _ex:
            print(_ex)
        finally:
            driver.close()
            driver.quit()

Ответы (0 шт):