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?
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>]