[英]Selenium 4 chrome devtools using Python fetch.fail_request not failing the request but keeping it as pending
在以下示例代碼中,fail_request 並未使請求失敗,而只是將其保持為掛起狀態。 我對 get_response_body 或fulfill_request 有類似的問題。
但是,允許繼續的所有請求(使用 continue_request)都沒有任何問題。
GeneralFunctions 的導入用於返回具有預定義操作的驅動程序對象的函數。 testSetup 的導入提供了對常用變量的訪問。
是否有什么我做錯了,或者這是與 Python 一起使用時的 Selenium 問題?
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.