Reputation: 65
I'm trying to get an iframe's src using selenium, but I cant find how to get the iframe inside a div (the div has an id). Here is what I have:
<div role="tabpanel" class="tab-pane active" id="video_box" style="background: #000; color: #fff;">
<iframe width="560" height="315" frameborder="0" src="https://embedsito.com/v/x431gb5q0rq76j-" scrolling="no" allowfullscreen=""></iframe>
</div>
As you can see, I can get the div by id using driver.find_element_by_id("video_box")
, but what I need is the src
from inside the div, and it has no class name, no id, no name and no text (well, it actually has text from the src but it changes every time). Is there any way of getting the iframe from inside the div and extract the src from it?
I've tried to use the find_by_css_selector('iframe')
method with no results
I've tried to use the find_element_by_tag_name('iframe')
method, but raises an exception:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: iframe
Upvotes: 0
Views: 413
Reputation: 46
Have you tried to go into the developer tools (inspect element) and get the XPath of the iframe by right-clicking on it?
Then you could use the command find_element_by_xpath()
method.
Upvotes: 1