Using Selenium for Browser Automation
This module provides comprehensive browser automation capabilities using Selenium WebDriver with undetected Chrome support.
Overview
The automation module enables:
- Undetected Browser Control: Uses undetected_chromedriver to avoid detection
- Text-based Element Finding: Locate elements by visible text content
- Visual Element Matching: Use Airtest for image-based element detection
- Page State Monitoring: Wait for HTML and visual stabilization
- Document Conversion: Convert Markdown with Ruby annotations to PNG/PDF
Core Components
- Browser initialization and management
- Element finding strategies (text-based and visual)
- Page waiting and monitoring utilities
- Screenshot and document generation tools
pip install undetected_chromedriver webdriver_manager
# from selenium.webdriver.chrome.service import Service
# from webdriver_manager.chrome import ChromeDriverManager
# def init(*arguments):
# chrome_options = webdriver.ChromeOptions()
# for argument in arguments:
# if isinstance(argument, str):
# chrome_options.add_argument(argument)
# global driver
# driver = webdriver.Chrome(
# options = chrome_options,
# service = Service(ChromeDriverManager().install())
# )
# global device_pixel_ratio
# device_pixel_ratio = driver.execute_script('return window.devicePixelRatio;')
init('--user-data-dir=C:\\Users\\seii-saintway\\Downloads\\chrome-profile')
pip install airtest
pip install markdown
init('--lang=en')
convert_md_with_ruby_to_png('2024-11-21.md')
convert_md_with_ruby_to_pdf('2024-11-21.md')