Browser Remote Control

The setup on this page is done with a fresh ubuntu desktop 20.04 lts installation.

The final script fetches all account balances from a REST endpoint, and prints the results on the command line.

Firefox runs headless, and is controlled by Selenium with Python.

Install dependencies:

sudo apt install python3 python3-pip
pip3 install selenium
sudo apt install firefox-geckodriver

Script

#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import time

options = Options()
#options.headless = True
options.headless = False
browser = webdriver.Firefox(options=options)

browser.get("https://customer.somedomain.de/lp/wt/login?execution=e1s1")

# Cookies

browserWait = WebDriverWait(browser, 10)
element = browserWait.until(EC.element_to_be_clickable((By.ID, "uc-btn-more-info-banner")))
element.click()
time.sleep(0.5)
element = browserWait.until(EC.element_to_be_clickable((By.CLASS_NAME, "uc-save-settings-button")))
element.click()
time.sleep(0.5)

# Login

browser.find_element(By.ID, "param1Input").send_keys("<USERID>")
browser.find_element(By.ID, "param3Input").send_keys("<USERPIN>")
browser.find_element(By.ID, "loginAction").click()

# Account Balances

accountTableClass = browser.find_element(By.CLASS_NAME, "table--list")
accountTable = accountTableClass.find_element(By.TAG_NAME, "tbody")
accountRows = accountTable.find_elements(By.TAG_NAME, "tr")
for row in accountRows:
  accountColumns = row.find_elements(By.TAG_NAME, "td")
  print("Name: " + accountColumns[0].text)
  print("Kontostand: " + accountColumns[4].text)

# Logout

browser.find_element(By.ID, "llLink").click()
browserWait.until(EC.text_to_be_present_in_element((By.TAG_NAME, "h1"), "You logged out successfully"))
browser.close()

Result

$ ./get_balances.py
Name: Das tolle Konto
Kontostand: 10,00 €
Name: Ein ganz anderes Konto
Kontostand: 101,12 €

Further Readings

Reach out to me for professional support!

Contact