【问题标题】:Python selenium webdriver - stop a repeating AJAX requestPython selenium webdriver - 停止重复的 AJAX 请求
【发布时间】:2016-12-04 17:20:42
【问题描述】:

以下是在浏览器中复制问题的过程: 例如,http://www.zulutrade.com/trader/314609?t=30 如果您点击“交易历史”右侧的“未平仓头寸”,您将收到一个重复的 AJAX 请求。

在我的代码中,我需要知道如何在执行后停止它:

open_pos_table_sel = "#table-view-open-positions+ label"


open_positions_el = br.find_element_by_css_selector(open_pos_table_sel)
br.execute_script("arguments[0].click()", open_positions_el)

通过javascript执行点击的代码是什么。

显然你可以在 Java 中使用 selenium 禁用 jQuery,但是我找不到在 python 中执行此操作的方法...

selenium.waitForCondition(
        "selenium.browserbot.getCurrentWindow().jQuery.active == 0",
        timeout);

【问题讨论】:

    标签: python selenium selenium-chromedriver


    【解决方案1】:

    尝试直接删除jquery并替换xhr send:

    driver.execute_script("window.oldjQuery=window.jQuery;delete window.jQuery;delete window.$;window.oSend=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.send = function(){console.log('stopped ajax request', arguments)};")
    

    然后把 jQuery 和 xhr 发回:

    driver.execute_script("window.jQuery=window.oldjQuery;window.$=window.jQuery;XMLHttpRequest.prototype.send=window.oSend")
    

    参考来自:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多