Skip to content

Instantly share code, notes, and snippets.

@detrin
Created August 5, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detrin/cc56f27dd72d4d0cc9c9a79a9758f77c to your computer and use it in GitHub Desktop.
Save detrin/cc56f27dd72d4d0cc9c9a79a9758f77c to your computer and use it in GitHub Desktop.
Testing selenium with chromium-chromedriver on Raspberry Pi
from pyvirtualdisplay import Display
from selenium import webdriver
import time
import numpy as np
display = Display(visible=0, size=(1920, 1080))
display.start()
options = webdriver.ChromeOptions()
options.add_argument("--kiosk")
driver = webdriver.Chrome(options=options)
# Take screenshot
driver.get('https://example.com')
driver.save_screenshot("screenshot.png")
# Test average loading time
time_deltas = []
for i in range(12):
time_flag = time.time()
# Scraping example
driver.get('https://pandas.pydata.org')
button = driver.find_element_by_css_selector("#nav-content > ul > li:nth-child(3) > a")
button_text = button.text
elapsed_time = (time.time()-time_flag) / 12
time_deltas.append(elapsed_time)
print(f"run: {i}\t text: {button_text}\t elapsed time: {elapsed_time:7.4f} s")
print(f"elapsed time per run {np.mean(time_deltas):7.4f} +/- {np.std(time_deltas):7.4f} s")
driver.quit()
display.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment