Need to select an IFrame with selenium (python)

0 votes

I want to select an iframe and I am not able to do it now. Below is the HTML where I want to make it work:

<iframe id="upload_file_frame" width="100%" height="465px" frameborder="0" framemargin="0" name="upload_file_frame" src="/blah/import/">
        <div class="import_devices">
            <div class="import_type">
                <a class="secondary_button" href="/blah/blah/?source=blah">
                    <div class="import_choice_image">
                        <img alt="blah" src="/public/images/blah/import/blah.png">
                    <div class="import_choice_text">Blah Blah</div>

My python code for finding the iframe is this:

def test_pedometer(self):
    sel = self.selenium
    for i in range(5):
            if sel.select_frame("css=#upload_file_frame"): break
        except: pass
    else:"Cannot find upload_file_frame, the iframe for the device upload image buttons")

At times this code works, but something si wrong and Selenium just fails most times. Not sure if the issue is because of some race condition or something? Can someone lead me in the right path?

May 3, 2018 in Selenium by eLiJha
• 720 points

1 answer to this question.

0 votes

Well for me, something like this worked. I've done inserting data within an iframe:

self.driver = webdriver.Firefox()

## Give time for iframe to load ##

## You have to switch to the iframe like so: ##

## Insert text via xpath ##
elem = driver.find_element_by_xpath("/html/body/p")
elem.send_keys("Lorem Ipsum")

## Switch back to the "default content" (that is, out of the iframes) ##
answered May 3, 2018 by sniffy_god
• 780 points

Related Questions In Selenium

0 votes
1 answer

Need to scroll down for locating an Element with Selenium

There are a couple of options for ...READ MORE

answered Apr 20, 2018 in Selenium by king_kenny
• 3,650 points
0 votes
1 answer
0 votes
1 answer

Need to perform parallel execution (multiple browser sessions) with Selenium & TestNG by using @BeforeSuite

@Beforesuite annotated method runs before the testNG.XML ...READ MORE

answered Mar 30, 2018 in Selenium by nsv999
• 5,090 points
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
+2 votes
1 answer

I want the console.log output from Chrome. I'm working with selenium on Python

So this is how you do it ...READ MORE

answered May 3, 2018 in Selenium by sniffy_god
• 780 points
+1 vote
2 answers