Skip to content

Instantly share code, notes, and snippets.

@Bostwickenator
Created November 19, 2022 15:41
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 Bostwickenator/2d2a85727ffda0c0e04fa2494fc1daa4 to your computer and use it in GitHub Desktop.
Save Bostwickenator/2d2a85727ffda0c0e04fa2494fc1daa4 to your computer and use it in GitHub Desktop.
Login to Smart Meter Texas with Selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time
import random
def slow_type(element, text, delay=0.04):
"""Send a text to an element one character at a time with a delay."""
for character in text:
element.send_keys(character)
time.sleep(random.random())
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-plugins-discovery");
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument( '--disable-blink-features=AutomationControlled' )
browser = webdriver.Chrome(chrome_options=chrome_options)
time.sleep(5)
browser.get('https://www.smartmetertexas.com/')
time.sleep(1.123)
user = browser.find_element(By.ID, 'userid')
user.click()
slow_type(user,"USER_NAME")
time.sleep(1.2)
password = browser.find_element(By.ID, 'password')
password.click()
slow_type(password,"PASSWORD_HERE")
time.sleep(1)
password.send_keys(Keys.RETURN)
#login = browser.find_element(By.ID, 'loginform').find_element(By.CLASS_NAME, 'btn')
#login.click()
wait = WebDriverWait(browser,100)
wait.until(EC.url_matches('https://www.smartmetertexas.com/dashboard/'))
time.sleep(15)
print(browser.execute_script("return JSON.parse(window.localStorage.smt_user)['token'];"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment