Files
guide/test_selenium_debugger_address.py

82 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Test Selenium debugger_address connection to verify no page refresh."""
import sys
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def main():
print("=== Selenium debugger_address Connection Test ===\n")
# CDP connection parameters
host = "192.168.50.185"
port = 9223
print(f"Connecting to Chrome via debugger_address at {host}:{port}...")
try:
# Configure Chrome options to connect to existing browser
chrome_options = Options()
chrome_options.debugger_address = f"{host}:{port}"
# Connect to existing browser (no WebDriver executable needed)
driver = webdriver.Chrome(options=chrome_options)
print("✓ Connected successfully!")
# Get initial state
initial_url = driver.current_url
print(f"\nInitial URL: {initial_url}")
# Get page title
title = driver.title
print(f"Page title: {title}")
# Wait a moment
print("\nWaiting 2 seconds to observe page state...")
time.sleep(2)
# Check URL again to see if page refreshed
current_url = driver.current_url
print(f"Current URL: {current_url}")
# Check if page refreshed
if initial_url == current_url:
print("\n✓✓✓ SUCCESS: Page did NOT refresh on connection! ✓✓✓")
else:
print("\n✗✗✗ FAILURE: Page URL changed (possible refresh) ✗✗✗")
print(f" Before: {initial_url}")
print(f" After: {current_url}")
# Try a simple interaction to further test
print("\nTrying to get HTML length as an interaction test...")
html = driver.page_source
print(f"HTML length: {len(html)} characters")
# Final URL check
final_url = driver.current_url
print(f"Final URL: {final_url}")
if initial_url == final_url:
print("\n✓✓✓ FINAL RESULT: No refresh detected! ✓✓✓")
else:
print(f"\n✗✗✗ FINAL RESULT: URL changed! ✗✗✗")
# Clean up
print("\nClosing connection...")
driver.quit()
print("Done!")
except Exception as e:
print(f"\n✗✗✗ ERROR: {type(e).__name__}: {e} ✗✗✗")
import traceback
traceback.print_exc()
return 1
return 0
if __name__ == "__main__":
exit(main())