python - 使用 python 模块 selenium 在浏览器中输入

标签 python python-3.x selenium

我的老师让我们使用这个网站来提高我们的打字技巧。我们的作业将于下个月到期,我太懒了,想使用 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/

相关文章:

python - 如何读取文件并逐行处理

python-3.x - 文本规范化 : Text similarity in Python. 如何规范文本拼写不匹配?

python - 编辑子类中的选项卡名称

ruby-on-rails - 如何用 capybara 和 Selenium 填充tinymce-rails编辑器?

java - 如何在 Java (Selenium) 设置中使用 Apache POI 多个线程(并行测试用例)同时访问同一个 Excel 文件?

python - 从 Python 中的直方图中获取数据点

python - 使用 gdata 的托管域的 google 数据 API 的 OAuth 身份验证失败

python - 如何创建一个不断更新的全局变量?

python-3.x - 如何使用aiohttp检查url状态码?

java - 无法使用 selenium 脚本在 mozilla firefox 中写入 URL。即使eclipse也没有显示任何错误