How to compare two selenium WebElements to see if they are the same ?
First I retrieve a list of input_fields
and the first_input
element:
self.input_fields = driver.find_elements(By.CLASS_NAME, class_name)
self.first_input = driver.find_element(By.ID, id)
Then I try to check if input_fields[0]
and first_input
are the same WebElement.
if self.first_input is not self.input_fields[0]:
self.__log.warning("WebElement first_input : {} != {}".format(self.first_input, self.input_fields[0]))
Though the session
and element
are the same, the warning message is in any case triggered.
WARNING - WebElement first_input: <selenium.webdriver.remote.webelement.WebElement (session="796bf0bcf3e0df528ee932d477951689", element="94a2ee62-9511-45e5-8aa3-bd3d3e9be309")> != <selenium.webdriver.remote.webelement.WebElement (session="796bf0bcf3e0df528ee932d477951689", element="94a2ee62-9511-45e5-8aa3-bd3d3e9be309")>