My internet connection was slow intermittently, so I needed a way to automatically collect throughput information several times a day. The internet service provider (Unitymedia in this case) has a speedtest page that's pretty useful for that, but it requires manual clicking a button every time. Not very practical for automated collection.
Turns out with Selenium this is pretty easy to automate. I did use the python API with chrome on Ubuntu 17.10, with following packages:
The example code below runs the speedtest, collects the results and prints them to stdout in a somewhat structured way after the test run.
Update (2018-02-05): The script collects ping time as well now.
#!/usr/bin/env python3
import time
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
= webdriver.Chrome(executable_path="/usr/lib/chromium-browser/chromedriver")
browser 'https://speedtest.unitymedia.de/')
browser.get(2)
browser.implicitly_wait(
assert 'Unitymedia' in browser.title
"Weiter zum Internet Speedtest").click()
browser.find_element_by_link_text("icon-unitymedia-cable").click()
browser.find_element_by_id("speedtest-btn--primary").click()
browser.find_element_by_class_name(
= (WebDriverWait(browser, 60)
result_link lambda x: x.find_element_by_link_text("Details & alte Ergebnisse ansehen")))
.until(
result_link.click()
"speedtest-toggle-header").click()
browser.find_element_by_class_name(= browser.find_element_by_class_name("speedtest-toggle-header")
results = results.get_attribute("data-test-id")
results_id = results.find_element_by_class_name("day").text
results_day = results.find_element_by_class_name("time").text
results_time = (results
results_download "download")
.find_element_by_class_name("number")
.find_element_by_class_name(
.text)= (results
results_upload "upload")
.find_element_by_class_name("number")
.find_element_by_class_name(
.text)
= browser.find_element_by_class_name("speedtest-toggle-wrapper")
result_details = (result_details
result_ping "ping-result")
.find_element_by_class_name("speed")
.find_element_by_class_name("number0")
.find_element_by_class_name(
.text)
print("{};\t{};\t{};\t{};\t{};\t{};"
format(results_day, results_time, results_download,
.
results_upload, result_ping, results_id)) browser.quit()