python-3.x - Python Selenium:键盘无法访问元素 - 如何解决?与WCAG标准有关吗?
问题描述
我正在尝试在 Windows 中使用 Selenium 和 Python 3.8.1 登录网站,这是我卡住的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options)
driver.implicitly_wait(0.25)
driver.get('https://www.awebsite.com')
elem = driver.find_element_by_name('userLogin')
elem.send_keys('chuu@blockberry.com')
我的错误信息:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <input id="ft_username" name="userLogin" type="text"> is not reachable by keyboard
我尝试使用 xpath 和 id 而不是 name 进行选择,结果是相同的。
在试图弄清楚这一点时,我尝试在 Firefox 中“检查可访问性属性”只是为了看看它做了什么,并注意到我试图输入文本的字段有两个警告:
Does not meet WCAG standards for keyboard accessibility
Does not meet WCAG standards for text alternative
这似乎以某种方式相关,但我不知道这意味着什么或如何使用此信息来解决问题。我想如果我是网站开发人员,我可以尝试使其符合 WCAG 标准,但我是一个被这个网站所困扰的用户,那么我如何在 Python 中解决这个问题呢?
解决方案
css 选择器来自 (.login-form > div:nth-child(2) > form:nth-child(1) > div:nth-child(1) > input:nth-child(2)
该元素无法访问,因此请使用上面的 css 选择器。
推荐阅读
- mysql - 从双联表中选择最大值
- azure - 从 Azure Web App 访问本地数据库
- javascript - 在 D3 JS 中显示半甜甜圈饼图的值
- c - 无法获取客户端通过 TCP 发送的消息
- c# - 如何在 wix 安装程序中获取 .msi 运行位置?
- ruby-on-rails - 从 Ruby 文件访问 Pry 的 show-source 方法
- javascript - 函数转换为箭头函数 - 函数未定义
- java - Spring 控制器 RequestMapping PathVariable 中 URL 的零长度部分中断解析
- c# - 为什么 Visual Studio 从我的代码中删除静态?
- c# - 从 DataTemplate 中的 userControl 触发 listboxItem 可见性