Selenium Webdriver false negative result for testing visibility of an element? Selenium Webdriver false negative result for testing visibility of an element? selenium selenium

Selenium Webdriver false negative result for testing visibility of an element?


I am pretty sure this id cannot be unique since it is in ng-repeat and it's probably loading more than one elements with same id which is not safe to use.

With that being said and since, you also mentioned element load is not an issue, it safe to assume that the selector is probably returning some other element which is actually hidden. I experienced something similar before where selenium actually found the element which was hidden and was not the intended one. You can actually use len() with find_elements_by_css_selector() to see how many elements were returned.

Use ng-attr-id="{{toolbarButton.id}}" or whatever displayed on client in cojuntion with [id='image'][ng-attr-id='something'] as cssSelector


The key difference between running the code in the Python terminal and running it as a script is that on terminal you have pauses/delays between every line you execute - this gives the page time to process asynchronous requests, update the DOM etc. In your test code, you need to wait for the element to become visible:

from selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECwait = WebDriverWait(driver, 10)image = wait.until(EC.visibility_of_element_located((By.ID, "Image")))