Python automatically login to web-based router portal to check sms

I recently purchased a Huawei mobile router which has a web-based portal, but the portal automatically logs me out when I switch tabs (security feature) but I use the portal for text messages and would like to create a script that I could run when using my laptop,

There are three web pages involved in this process

Portal Login Page: http://192.168.8.1/html/index.html

Login Page

Portal Home Page: http://192.168.8.1/html/content.html#home

Home Page

Portal Sms Page: http://192.168.8.1/html/content.html#sms

Sms Page

So I have managed to get somewhere with a python script.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time 

def login_process():
  passwordStr = 'myPassword'
  browser = webdriver.Chrome()
  browser.set_window_size(900, 800)
  browser.get(('http://192.168.8.1/html/index.html'))
  username = browser.find_element_by_id('login_password')
  username.send_keys(passwordStr)
  signInButton = browser.find_element_by_id('login_btn')
  signInButton.click()
  time.sleep(3)
  browser.get(('http://192.168.8.1/html/content.html#sms'))
  time.sleep(2)
  html = browser.find_element_by_tag_name('html') 
  html.send_keys(Keys.END)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  html.send_keys(Keys.ARROW_RIGHT)
  time.sleep(10)
login_process()

But now I am struggling to find a way so that If i manually click into the browser window at the end of the function it will stay open as it automatically closes if i don't have time.sleep(10)

and I also want the function to auto run every 10 minutes until I close the script, like say I want to watch a movie.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation