My webpage supports keyboard navigation where pressing the "TAB" key switches focus across the webpage items in a specific order. Pressing Enter key on a focussed item opens the popup/selects that item.
My test cases for automation are: 1. Press Tab key across the website and verify the correct item is in focus. 2. Press Enter key on a focussed item and verify that the popup is displayed. 3. Press Enter key on a focussed item and verify that it is selected.
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?
Thanks for your help