Failed login using Python (selenium) - what works with v-on:click="submitForm"?

88 Views Asked by At

Can I use selenium or do I need a different module in order to click this kind of button? and what is the related code please?..... see details as follows and thanks for your help in advance.

I am a newbie to coding altogether. Slowly learning Python.

Current project is logging into trading website - my code is failing on last button click.

The HTML related to the button includes: v-on:click="submitForm" :disabled="isSubmit"

From a quick search this is Vue.js which I am not familiar with.

Ps my very first coding question!


ERROR MESSAGE:

line 21, in
login_button.click()
AttributeError: 'list' object has no attribute 'click'


WRITTEN CODE:

from selenium import webdriver

USERNAME = 'XXXXXX'<br>
PASSWORD = 'YYYYYY'

PATH = 'C:\Program Files (x86)\chromedriver.exe'
driver = webdriver.Chrome(PATH)

driver.get('https://www.nabtrade.com.au/investor/home')<br>
open_login_button = driver.find_element_by_id('btn-login')<br>
open_login_button.click()

user_input = driver.find_element_by_id('usernameField')<br>
user_input.send_keys(USERNAME)

password_input = driver.find_element_by_id('passwordField')<br>
password_input.send_keys(PASSWORD)

*login_button = driver.find_elements_by_class_name('btn btn-primary btn-block')*<br>
*login_button.click()*

NOTE: last two line of code are the ones failing

2

There are 2 best solutions below

1
cruisepandey On BEST ANSWER
line 21, in
login_button.click()
AttributeError: 'list' object has no attribute 'click'

the above error is because you are using find_elements instead of find_element.

find_elements

will return a list of web element in Selenium Python bindings.

where as

find_element

returns a single web element.

I see you are using class name with spaces, that is not supported by Selenium-Python, try switching to xpath :

Your code should look like this :

login_button = driver.find_element_by_xpath("//button[text()='Login']")
login_button.click()
1
Prophet On

Instead of

login_button = driver.find_elements_by_class_name('btn btn-primary btn-block')

Try using

login_button = driver.find_element_by_class_name('btn btn-primary btn-block')

find_element_by_class_name returns a list of web elements, you can not click on a list, only on specific, single element