Created
January 11, 2024 20:15
-
-
Save Luigi-Pizzolito/2cce26d13d9a3730800c686e83404a9c to your computer and use it in GitHub Desktop.
Automatic login to Wifi using Selenium
This file contains hidden or 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.keys import Keys | |
from selenium.webdriver.chrome.options import Options | |
import time | |
# Set the path to your chromedriver executable | |
url = 'http://10.0.0.55' | |
# Set up Chrome options for headless mode | |
chrome_options = Options() | |
chrome_options.add_argument('--headless') # Run Chrome in headless mode | |
# Create a new instance of the Chrome driver with the specified options | |
driver = webdriver.Chrome(options=chrome_options) | |
# Open the specified URL | |
driver.get(url) | |
time.sleep(2) | |
try: | |
# Find the username input field | |
username_input = driver.find_element('id', 'username') | |
# Check if the type attribute is 'hidden' | |
if username_input.get_attribute('type') != 'hidden': | |
print("Logging in.") | |
# Set the value of the username field | |
username_input.send_keys('username_here') | |
time.sleep(0.2) | |
# Find the password input field | |
password_input = driver.find_element('id', 'password') | |
# Set the value of the password field | |
password_input.send_keys('password_here') | |
time.sleep(0.2) | |
# Find the remember login button and click it | |
remember_checkbox = driver.find_element('id', 'remember') | |
remember_checkbox.click() | |
# Find the login button and click it | |
login_button = driver.find_element('id', 'login') | |
login_button.click() | |
time.sleep(2) | |
else: | |
print("Already logged in.") | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
finally: | |
# Close the browser window | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment