# Login form handler runescape.com
def runescape_login(driver, username, password):
# On runescape account login screen
print("On the login page")
username_field = driver.find_element_by_id("login-username")
password_field = driver.find_element_by_id("login-password")
print("Placing log in credentials")
if username not in username_field.text:
username_field.clear()
print("Filling username data")
username_field.send_keys(username)
print("Filling password data")
password_field.send_keys(password)
if runescape_site_key in driver.page_source:
# Generates the captcha token and executes javascript
print("RecaptchaV2")
captcha_id = get_captcha_id(runescape_login_url, runescape_site_key)
captcha_token = get_captcha_token(captcha_id)
driver.execute_script("document.getElementById('g-recaptcha-response').innerHTML = '"
+ captcha_token + "'; onSubmit();")
time.sleep(3)
pass
else:
print("Clicking the login button")
driver.find_element_by_id("du-login-submit").click()