javascript - Selector that confirms image loaded using Selenium Python API -
i looking way confirm image has loaded. maybe javascript option? using right webdriverwait
force wait on images, actual src
, run tests after...
wait = webdriverwait(driver, 10) ... albums = wait.until(ec.presence_of_all_elements_located((by.css_selector, ".albums .album img"))) albumslength = len(albums)-1 while albumslength > 0: wait.until(ec.presence_of_element_located((by.css_selector, ('.album:nth-child('+str(albumslength)+') img[src*="album-foo"]')))) albumslength -= 1 ...
this @ point confirm "album-foo" exists in <img src="http://www.album-foo/images/blah.jpg"
of each album in albums. not confirm image completed loading view. have searched high , low, have solution?
i testing on chrome , firefox, no phantom or ie restrictions, if ideas grow including javascript or related ideas might have environment restrictions.
i not experienced selenium, though give try. if want check whether image loaded, i'd use boolean. set original value of boolean let's 'loaded' false.
then call this, making sure returns true moment image has loaded.
boolean loaded = false; webdriver driver = new anydriveryouwant(); javascriptexecutor js; if (driver instanceof javascriptexecutor) { js = (javascriptexecutor)driver; } loaded = (boolean)js.executescript("image.onload(function() { return true; });");
Comments
Post a Comment