# Find first element with textlogin_button = await tab.find("Login")# Best match (most similar text length)login_button = await tab.find("Login", best_match=True)# Find all elements with textall_links = await tab.find_all("Click here")
# Find single elementbutton = await tab.select("button[type='submit']")# Find all matching elementslinks = await tab.select_all("a[href]")# Include elements in iframesall_inputs = await tab.select_all("input", include_frames=True)
# Wait for element by selectorelement = await tab.wait_for(selector="#dynamic-content")# Wait for element by textelement = await tab.wait_for(text="Loading complete")# Custom timeoutelement = await tab.wait_for(selector=".notification", timeout=30)
# Navigate current tabawait tab.get("https://example.com")# Open in new tabnew_tab = await tab.get("https://example.com", new_tab=True)# Open in new windownew_window = await tab.get("https://example.com", new_window=True)
# Evaluate and get resultpage_title = await tab.evaluate("document.title")# Wait for promise to resolveresult = await tab.evaluate( "fetch('https://api.example.com/data').then(r => r.json())", await_promise=True)# Get deep serialized valuedeep_obj = await tab.evaluate( "window.someComplexObject", return_by_value=False)
# Save screenshot to fileawait tab.save_screenshot("page.jpg")# Capture full pageawait tab.save_screenshot("fullpage.png", format="png", full_page=True)# Get base64 encoded database64_data = await tab.screenshot_b64(format="jpeg")
# Scroll down 50% of pageawait tab.scroll_down(amount=50)# Scroll up 25% of pageawait tab.scroll_up(amount=25)# Control scroll speed (pixels per second)await tab.scroll_down(amount=100, speed=1200)
from zendriver.cdp.fetch import RequestStagefrom zendriver.cdp.network import ResourceType# Intercept and modify requestsasync with tab.intercept( url_pattern="*api.example.com*", request_stage=RequestStage.REQUEST, resource_type=ResourceType.XHR) as interceptor: async for request in interceptor: # Modify or block request await request.continue_()
# Wait for specific requestasync with tab.expect_request(r".*api/data.*") as request: await button.click()print(f"Request URL: {request.url}")# Wait for responseasync with tab.expect_response(r".*api/data.*") as response: await button.click()print(f"Status: {response.status}")