简体   繁体   English

使用 Python fetch.fail_request 的 Selenium 4 chrome devtools 不会使请求失败,而是将其保持为待处理

[英]Selenium 4 chrome devtools using Python fetch.fail_request not failing the request but keeping it as pending

In the following sample code the fail_request is not failing the request but simply keeping it as pending.在以下示例代码中,fail_request 并未使请求失败,而只是将其保持为挂起状态。 I have similar issues with get_response_body or fulfill_request.我对 get_response_body 或fulfill_request 有类似的问题。

However all requests that are let to continue (using continue_request) are without any issues.但是,允许继续的所有请求(使用 continue_request)都没有任何问题。

The import for GeneralFunctions is used for a function that returns a driver object with predefined actions. GeneralFunctions 的导入用于返回具有预定义操作的驱动程序对象的函数。 The import for testSetup provides access to generally used variables. testSetup 的导入提供了对常用变量的访问。

Is there something that I am doing wrong or is this a Selenium issue when using it with Python?是否有什么我做错了,或者这是与 Python 一起使用时的 Selenium 问题?

  • Python version: 3.10 Python版本:3.10
  • Selenium webdriver version: 4.3.0 Selenium 网络驱动程序版本:4.3.0
  • Webdriver-manager version: 3.8.0 (used to download the latest chrome driver). Webdriver-manager 版本:3.8.0(用于下载最新的chrome驱动)。
  • Trio version: 0.20.0三重奏版本:0.20.0
  • Chrome version: 103铬版本:103
import trio
import time
from Setup.Setup import testSetup
from Setup.General import GeneralFunctions
from selenium.webdriver.common.by import By
generalFunctions = GeneralFunctions()
async def main1():
    driver = generalFunctions.newChrome(testSetup.url)
    time.sleep(6)
    async with driver.bidi_connection() as connection:        
        session, devtools = connection.session, connection.devtools
        await session.execute(devtools.fetch.enable())
        listener = session.listen(devtools.fetch.RequestPaused)
        async with trio.open_nursery() as nursery:
            driver.refresh()
            async for event in listener:
                if "userData" in str(event.request.url) and event.request.method == "GET":
                    try:
                         await session.execute(devtools.fetch.fail_request(event.request_id, '{"error_reason": "aaaa"}'))
                        
                    except:
                        print("problem with target request")
                else:
                    try:
                        await session.execute(devtools.fetch.continue_request(event.request_id))
                    except:
                        print("problem with regular request")


async def main2():
    await main1()


trio.run(main2)

我自己想出来了 - 我没有检查异常错误,问题是 fetch.fail_request 需要第二个参数是这样的:

await session.execute(devtools.fetch.fail_request(event.request_id, devtools.network.ErrorReason.FAILED))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM