我的老师让我们使用这个网站来提高我们的打字技巧。我们的作业将于下个月到期,我太懒了,想使用 python 模块 selenium 制作一个程序。一切都按计划进行,接受一件事,我如何在浏览器上打字。您无需在文本框中输入内容。这是我的代码:
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()
这是代码执行完毕后屏幕的样子:the website 。我尝试使用 send_keys('6') 但这不起作用。网站代码如下:the website code 。再次强调,如果有办法直接在浏览器上键入按键,请立即告诉我。
最佳答案
有,试试 PyAutoGui模块。可以用pip安装,可以按键。按 y 键的示例:
import pyautogui
pyautogui.press('y')
关于python - 使用 python 模块 selenium 在浏览器中输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46106705/