Created
November 19, 2022 15:41
-
-
Save Bostwickenator/2d2a85727ffda0c0e04fa2494fc1daa4 to your computer and use it in GitHub Desktop.
Login to Smart Meter Texas with Selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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