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

孤街浪徒 提交于 2019-12-06 09:18:34

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 WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


wait = WebDriverWait(driver, 10)
image = wait.until(EC.visibility_of_element_located((By.ID, "Image")))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!