我使用 selenium-wire
和 requests
打印网络 URL、状态代码和一些标题属性。我希望 selenium 等到所有 url 都打印完再进入下一页。
如何添加等待相同的内容?
我的代码:
from seleniumwire import webdriver
import pytest
from selenium.webdriver.chrome.options import Options
import time
class Test_main():
@pytest.fixture()
def test_setup(self):
# initiating browser
chrome_options = Options()
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--headless')
self.driver = webdriver.Chrome(executable_path=r"D:/Python/Sel_python/drivers/chromedriver v86/chromedriver.exe", options=chrome_options)
# terminate script
yield
self.driver.close()
self.driver.quit()
print("Test completed")
def testcase_01(self, test_setup):
self.driver.get("https://lifesciences.cactusglobal.com/")
title = self.driver.title
print("Page title: " + title)
time.sleep(3)
self.driver.find_element_by_xpath("//a[contains(text(),'here')]").click()
self.driver.find_element_by_xpath("//a[contains(text(), 'Allow all')]").click()
time.sleep(5)
for request in self.driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type'],
request.response.headers['set-cookie']
)
self.driver.find_element_by_xpath("//a[contains(text(),'next')]").click()
我尝试添加 time.sleep
,但它会停止整个驱动程序,并在恢复时跳转到下一个 url。
有没有办法使用 webdriverwaits
处理这个问题?