我需要帮助这是我的脚本:
# Imports
from selenium import webdriver
url = "https://sjc.cloudsigma.com/ui/4.0/login"
d = webdriver.Chrome()
d.get(url)
escolhe = d.find_elements_by_xpath('//*[@id="trynow"]')
escolhe.click()
这就是html的外观:
<button id="trynow" class="btn g-recaptcha block full-width m-b dwse btn-warning" ng-class="{'btn-danger': instantAccess=='Error', 'btn-success': instantAccess=='Success', 'btn-warning': instantAccess=='Working', 'btn-warning': (instantAccess!='Working' && instantAccess!='Success' && instantAccess!='Error')}" data-ng-disabled="instantAccess=='Working' || instantAccess=='Success' || instantAccess=='Error'" analytics-on="click" analytics-event="Guest logged in" analytics-category="Guest logged in" analytics-label="Guest logged in" data-sitekey="6Lcf-2MUAAAAAKG8gJ-MTkwwwVw1XGshqh8mRq25" data-callback="onTryNow" data-size="invisible">
<span name="btn-warning" class="default " style="font-size: 20px;">
<i class="fa fa-thumbs-up"></i> Instant access
<p style="font-size: 9px;font-style: italic;margin: 2px 0px;" class="ng-binding">No credit card is required</p>
</span>
<span name="btn-warning" class="working hide" disabled=""><i class="fa fa-spinner fa-spin"></i> Instant access...</span> <span name="btn-success" class="success hide" disabled=""><i class="fa fa-spinner fa-spin"></i> Entrar na sessão</span> <span name="btn-danger" class="error hide" disabled=""><i class="fa fa-exclamation-circle"></i> Erro</span>
</button>
我需要帮助,因为每当我输入xpath时,都会出现以下错误:
AttributeError: 'list' object has no attribute 'click'
查找
element
而不是elements
必须写入元素而不是元素-->;即使只有一项,它也会将其视为列表。您必须这样修改:
此错误消息
…表示您已尝试在列表元素上调用
click()
方法,其中在WebElement上调用asclick()
解决方案
要单击所需的元素,可以使用以下任意一种Locator Strategies:
使用
css_selector
:使用
xpath
:理想情况下,要单击元素,需要为
element_to_be_clickable()
诱导WebDriverWait,并且可以使用以下Locator Strategies之一:使用
CSS_SELECTOR
:使用
XPATH
:注意:您必须添加以下导入:
相关问题 更多 >
编程相关推荐