【问题标题】:Python Selenium Ajax jquery: How to know when jquery (bootstrap) is done updating the page so I can take a screenshootPython Selenium Ajax jquery:如何知道 jquery(引导程序)何时完成更新页面,以便我可以截屏
【发布时间】:2021-09-13 22:58:48
【问题描述】:

我正在尝试在页面加载完成并完成所有 jquery 后截取屏幕截图。该页面在 IE、Edge 和 FireFox 中加载,但所有三种浏览器偶尔都会运行 jquery 有点慢,我得到一个 trasitional image 的 jquery 工作。

start_time = time.perf_counter()

ClickActionElement = Utility_Element_Verify.ID_Element(self,
            ElementID = ElementID,
            ElementDescription = ElementDescription)

webdriver.ActionChains(self.driver).move_to_element(ClickActionElement).perform()
webdriver.ActionChains(self.driver).move_to_element(ClickActionElement).click(ClickActionElement).perform()
WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID , WaitElementID)))

end_time = time.perf_counter()
time_elapsed = (end_time - start_time)
self.TestEventLog += "<br />LoadTime: Admin page and the Specific Ajax was completed before: " + str(time_elapsed) + " seconds"

在我截屏之前,我应该怎么做才能确保 jquery 在这里完成?

Utility_Capture_Screen.CaptureScreen(self)  # sometimes it's to fast

图像已保存,但有时 jquery 尚未完成。如何检测 jquery 是否已完成?

【问题讨论】:

    标签: python jquery selenium bootstrap-4


    【解决方案1】:

    使用jQuery.active 状态检查 jQuery 是否完成。在您的 WebDriverWait 中使用 lambda 来检查 jQuery 状态。

    wait = WebDriverWait(driver, 10)
    wait.until(lambda d: d.execute_script('return jQuery.active == 0'))
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 2010-10-09
      • 2012-12-23
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 2012-05-19
      • 1970-01-01
      相关资源
      最近更新 更多