Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type in browser using python module selenium

There is this website my teacher makes us use to improve our typing skills. Our assignment is due next month and I am too lazy and want to make a program using selenium, a python module. Everything is working according to plan accept one thing, how do I type on the browser. You don't type in a text box. Here is my code:

from selenium import webdriver

driver = webdriver.Chrome('/Users/iyadmajid/Desktop/chromedriver')
driver.set_page_load_timeout(30)
driver.get('https://www.typing.com/student/login')
driver.implicitly_wait(20)
driver.find_element_by_id('username').send_keys('the_username')
driver.find_element_by_name('password').send_keys('the_password')
driver.find_element_by_class_name('submit-login').click()
driver.find_element_by_xpath("//a[@href='/student/lessons/380/numeric-
keypad']").click()
driver.find_element_by_xpath("//a[@class='button begin-button tooltip-
trigger']").click()

This is what the screen looks like after the code finishes executing: the website. I tried using send_keys('6') but that doesn't work. Here is what website code looks like: the website code. Again, if there is a way to type keys on the browser directly, please let me now.

like image 384
John Adams Avatar asked Mar 20 '26 00:03

John Adams


1 Answers

There is, try the PyAutoGui module. It can be installed with pip and can press keys. An example that presses the y key:

import pyautogui
pyautogui.press('y')
like image 106
whackamadoodle3000 Avatar answered Mar 22 '26 23:03

whackamadoodle3000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!