6

I am trying to fill in fields on a login form with splinter. When I examine the rendered page, I see that the username input box has both a tag and a name of "u". How can I fill in this field from splinter? I tried the following:

from splinter import Browser

url = "http://www.weiyun.com/disk/login.html"
browser = Browser('firefox')
browser.visit(url)
browser.fill("u", "foo@bar.com")
print "done"

But there is no such field according to the error returned:

ElementDoesNotExist: no elements could be found with name "u"

How does one fill in the input fields on pages like this using splinter?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
user3677370
  • 63
  • 1
  • 3

1 Answers1

3

The problem is that your form is inside an iframe, use get_iframe() to interact with it:

with browser.get_iframe('_qq_login_frame') as iframe:
    iframe.fill("u", "foo@bar.com")

Demo to show the difference:

>>> browser = Browser('firefox')
>>> browser.visit(url)
>>> browser.find_by_name('u')
[]
>>> with browser.get_iframe('_qq_login_frame') as iframe:
...     iframe.find_by_name('u')
... 
[<splinter.driver.webdriver.firefox.WebDriverElement object at 0x102465590>]
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thank you very, very much! I haven't worked much with html before except for scraping simple pages - the whole iframe stuff is new to me and I'm reading up on it now. – user3677370 May 26 '14 at 22:44
  • I see how I can view the iframes with web developer in firefox. Knowing that I needed to interact with an iframe is the key piece of information I was missing. Is web developer in firefox the best way to figure out the structure of the page or are there better ones that you experienced guys use? – user3677370 May 26 '14 at 22:52
  • @user3677370 browser developer tools are must have and use, definitely. Glad it is solved. – alecxe May 26 '14 at 23:01
  • After filling in the username and password, I succeeded in pushing the login button, but for some reason, I needed to push it twice in my code. I wonder why it was necessary to push twice before login would happen? Is there more than one way to push the button? iframe.find_by_id("login_button").first.click() iframe.find_by_id("login_button").first.click() – user3677370 May 27 '14 at 02:49