0

I want to enter the email and the password directly with Splinter in Python. The problem is that it appears this message:

AttributeError: 'ElementList' object has no attribute 'fill'

The code I made is the following:

browser.find_by_id('email').first.find_by_tag('input').fill('test@gmail.com')
browser.find_by_id('password').first.find_by_tag('input').fill('mypassword')

'login_email' is the name of the Textbox, and it's of the type email. The same with the password. ¿Any help of why this isn't working?

Update: I tried the code of narzero but now it says it doesn't found the element: splinter.exceptions.ElementDoesNotExist: no elements could be found with id "email".

Pol MP
  • 23
  • 3
  • It seems that `find_by_name` return a list of Element. You expect an element. You have to check if your list is not empty and select the forst found (if it correspond to your needs) – RPresle Nov 23 '15 at 12:00
  • Thanks for your answer. I tried putting [0] or [1] after calling the fill function but isn't working anywhere – Pol MP Nov 23 '15 at 17:35
  • Have you tried the method from ElementList from Splinter? `list.first()`. What is the new error when you try to access the element? – RPresle Nov 23 '15 at 21:11

1 Answers1

1

After some research it seems someone had the same problem as you. find_by_name return an ElementList, so you have to select one of these Element. To do so you can use the first method of ElementList.

Here is some working code extracted from this post

# 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()

Thanks to narzero for this code.

Find the way that fit your needs

Community
  • 1
  • 1
RPresle
  • 2,436
  • 3
  • 24
  • 28
  • Thanks for your answer again. I tried to use the code above but now it says it doesn't found the element. It says: splinter.exceptions.ElementDoesNotExist: no elements could be found with id "email". And my code is: browser.find_by_id('email').first.find_by_tag('input').fill('email') – Pol MP Nov 24 '15 at 13:07
  • Well, the error is quite self explanatory. If you don't find the problem then you should post another question or edit this one with the delaration of your form. Just to be sure. In the question the name of your Textbox is login_email. You did not mistake here right ? =p – RPresle Nov 24 '15 at 21:19
  • You can check it yourself in the Paypal webpage haha. I tried everything and nothing works. I hope it isn't a secure method of Paypal – Pol MP Nov 26 '15 at 19:27
  • I think the better think to do is to create another question post. and provide HTML and python code. And put the link here in comment. Have you tried you code with your personal HTML code to validate your python? – RPresle Nov 26 '15 at 21:55