Philippe Blayo
Philippe Blayo

Reputation: 11030

Print dom when selenium misses an element I see

How to find what selenium see in a dom where it misses an image I see on screen?

Context: I have a Selenium python test

browser.wait_to_find_visible_element(By.ID, 'image')

that sometimes can't find an image that I see on the browser selenium launched for the test:

<div id="container">
    <img id='image' src=''/>
</div>

To find out what selenium see instead, I get the enclosing div:

element  = browser.find_displayed_elements(By.CSS_SELECTOR, '#container')
print element

which prints:

selenium.webdriver.remote.webelement.WebElement object at 0x9b3876c

and try to get the dom:

dom = browser.driver.execute_script('return arguments[0].parentNode', element)
print dom

which prints

None

What I'm missing?

Upvotes: 3

Views: 2653

Answers (1)

Amey
Amey

Reputation: 8548

Have you tried this

element  = browser.find_displayed_elements(By.CSS_SELECTOR, '#container')
source_code = element.get_attribute("innerHTML")
# or
source_code = element.get_attribute("outerHTML")

Upvotes: 1

Related Questions