Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filling in input fields with splinter

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", "[email protected]")
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?

like image 612
user3677370 Avatar asked May 26 '14 19:05

user3677370


1 Answers

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", "[email protected]")

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>]
like image 138
alecxe Avatar answered Oct 24 '22 09:10

alecxe