我的网页支持键盘导航,其中按“TAB”键以特定顺序在网页项目之间切换焦点。在焦点项目上按 Enter 键会打开弹出窗口/选择该项目。
我的自动化测试用例是: 1. 在整个网站上按 Tab 键并验证正确的项目是焦点。2. 在焦点项目上按 Enter 键并验证是否显示弹出窗口。3. 在焦点项目上按 Enter 键并确认它已被选中。
from selenium.webdriver.common.keys import Keys
# Qs: I want to test that the first time I press TAB key, the logo is in focus.
# Currently. I am unable to achieve that without finding that element.
# How do I include the first element in the test?
first = self.driver.find_element_by_id("logo")
# The following code tabs to the second item on the page and brings it in focus.
# Qs: How do I test that this item is in focus?
first.send_keys(Keys.TAB)
# How do I tab to the third item on the page without saving the second item
# in a variable?
# Do I need to find the element in focus in order to select it by sending the
# RETURN key?
谢谢你的帮助