首页 > 解决方案 > 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 中解决这个问题呢?

标签: python-3.xseleniumselenium-webdriver

解决方案


css 选择器来自 (.login-form > div:nth-child(2) > form:nth-child(1) > div:nth-child(1) > input:nth-child(2)

该元素无法访问,因此请使用上面的 css 选择器。


推荐阅读