Filling a password form with Splinter

做~自己de王妃 提交于 2019-11-30 16:35:11
narzero

Here is the working code:

from splinter import Browser     

# Define the username and password
username2 = '***'
password2 = '***'

# Choose the browser (default is Firefox)
browser2 = Browser()

# Fill in the url
browser2.visit('https://mijn.ing.nl/internetbankieren/SesamLoginServlet')

# Find the username form and fill it with the defined username
browser2.find_by_id('gebruikersnaam').first.find_by_tag('input').fill(username2)

# Find the password form and fill it with the defined password
browser2.find_by_id('wachtwoord').first.find_by_tag('input').fill(password2)

# Find the submit button and click
browser2.find_by_css('.submit').first.click()

# Print the current url
print browser2.url

# Print the current browser title
print browser2.title

# Print the current html source code
print browser2.html

The error indicates that you are trying to fill a list of elements. You need to select just one of the elements in the list. You probably want something like:

find_by_name('foo').first.fill()

Without getting too deep into your code, and taking a quick look at that site (where the ID's have changed, I might add), I would say you probably added an extra '#' into your find_by_id('#easnhbcc') call. The '#' is typical CSS language for an ID, but the find_by_id() splinter call does not expect it. either

find_by_id('easnhbcc')

or

find_by_css('#easnhbcc')

probably would have done the trick for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!