Selenium: Check if a WebElement has the focus Selenium: Check if a WebElement has the focus selenium selenium

Selenium: Check if a WebElement has the focus


There is another topic that covers this issue: Test if an element is focused using Selenium Webdriver

Basically the code will be

element.equals(driver.switchTo().activeElement());


for python developers:

def is_element_focus(id):    return self.driver.find_element_by_id(id) == self.driver.switch_to.active_element