<jupyter_start><jupyter_text>Playing with python and selenium SeleniumSelenium is a portable framework for testing web applications. Selenium provides a playback tool for authoring functional tests without the need to learn a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C, Groovy, Java, Perl, PHP, Python, Ruby and Scala. The tests can then run against most modern web browsers. Selenium runs on Windows, Linux, and macOS. It is open-source software released under the Apache License 2.0. GeckodriverThis program provides the HTTP API described by the WebDriver protocol to communicate with Gecko browsers, such as Firefox. It translates calls into the Marionette remote protocol by acting as a proxy between the local- and remote ends. Table of contents* [Installation](1)* [Getting Started](2)* [Navigating](3) Installation You need to install:- Python bindings for Selenium- Drivers (geckodriver for gecko browsers)If you have arch linux just run:<jupyter_code>!yes | sudo pacman -S python-selenium geckodriver<jupyter_output>Swipe your finger across the fingerprint reader<jupyter_text>If you have ubuntu linux run:<jupyter_code>%%bash
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
sudo sh -c 'tar -x geckodriver -zf geckodriver-v0.26.0-linux64.tar.gz-O > /usr/bin/geckodriver'
sudo chmod +x /usr/bin/geckodriver
rm geckodriver-v0.26.0-linux64.tar.gz<jupyter_output><empty_output><jupyter_text>If you have windows install linux :) Getting Started<jupyter_code>from selenium.webdriver.common.keys import Keys
from selenium import webdriver

# Creating instance of Firefox WebDriver
# The webdriver controls a browser by sending commands to a remote server.
driver = webdriver.Firefox()
# Navigate to a page given by the URL.
# WebDriver will wait until the page has fully loaded
driver.get("https://duckduckgo.com")
# Get search bar
search_bar = driver.find_element_by_id("search_form_input_homepage")
# Type Hello World!
search_bar.send_keys("<PASSWORD>!")
# "Press" return
search_bar.send_keys(Keys.RETURN)
driver.close()<jupyter_output><empty_output><jupyter_text>Navigating<jupyter_code>def get_grade(username, password):
    driver = webdriver.Firefox()
    driver.get("http://pithia.teithe.gr/unistudent/")
    driver.find_element_by_id("userName").send_keys(username)
    driver.find_element_by_id("pwd").send_keys(password)
    driver.find_element_by_id("submit1").click()
    driver.find_element_by_id("mnu3").click()
    
    page_source = driver.page_source
    driver.close()
    
    soup = BeautifulSoup(page_source, 'html.parser')
    
    return soup.find("tbody").find_all("tr")[len(soup.find("tbody").find_all("tr")[102])-10].find("span").getText()

#print(get_grade("username", "password"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09904371584699453, 'fraction_numerical': 0.011612021857923498, 'mean_word_length': 5.687214611872146, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '370164', 'license': 'MIT', 'n_tokens_mistral': 955, 'n_tokens_neox': 898, 'n_words': 270, 'path': 'pages/notes/ipynb/Selenium.ipynb', 'repo_name': 'DimitrisTzikas/DimitrisTzikas.github.io', 'size': '2929'}