0

我可以使用 selenium 还是需要其他模块才能单击这种按钮?请问相关代码是什么?.....请参阅以下详细信息,并提前感谢您的帮助。

我完全是编码的新手。慢慢学习Python。

当前项目正在登录交易网站 - 我的代码在最后一次单击按钮时失败。

与按钮相关的 HTML 包括:v-on:click="submitForm" :disabled="isSubmit"

通过快速搜索,这是我不熟悉的 Vue.js。

PS我的第一个编码问题!


错误信息:

第 21 行,在
login_button.click()
AttributeError: 'list' object has no attribute 'click'


书面代码:

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

注意:最后两行代码是失败的

4

2 回答 2

0

代替

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

尝试使用

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

find_element_by_class_name返回 web 元素列表,您不能单击列表,只能单击特定的单个元素

于 2021-07-06T11:02:02.910 回答
0
line 21, in
login_button.click()
AttributeError: 'list' object has no attribute 'click'

上述错误是因为您使用find_elements的是find_element.

find_elements

将返回 Selenium Python 绑定中的 Web 元素列表。

然而

find_element

返回单个 Web 元素。

我看到您正在使用带空格的类名,Selenium-Python 不支持,请尝试切换到xpath

您的代码应如下所示:

login_button = driver.find_element_by_xpath("//button[text()='Login']")
login_button.click()
于 2021-07-06T11:02:30.143 回答