<bdo id='ba1UE'></bdo><ul id='ba1UE'></ul>

<tfoot id='ba1UE'></tfoot>

    <small id='ba1UE'></small><noframes id='ba1UE'>

      <i id='ba1UE'><tr id='ba1UE'><dt id='ba1UE'><q id='ba1UE'><span id='ba1UE'><b id='ba1UE'><form id='ba1UE'><ins id='ba1UE'></ins><ul id='ba1UE'></ul><sub id='ba1UE'></sub></form><legend id='ba1UE'></legend><bdo id='ba1UE'><pre id='ba1UE'><center id='ba1UE'></center></pre></bdo></b><th id='ba1UE'></th></span></q></dt></tr></i><div id='ba1UE'><tfoot id='ba1UE'></tfoot><dl id='ba1UE'><fieldset id='ba1UE'></fieldset></dl></div>
    1. <legend id='ba1UE'><style id='ba1UE'><dir id='ba1UE'><q id='ba1UE'></q></dir></style></legend>

        AttributeError: 'list' 对象没有使用 Selenium 和

        时间:2023-10-14

          <legend id='e3o4z'><style id='e3o4z'><dir id='e3o4z'><q id='e3o4z'></q></dir></style></legend>
          <tfoot id='e3o4z'></tfoot>

              <bdo id='e3o4z'></bdo><ul id='e3o4z'></ul>

              <small id='e3o4z'></small><noframes id='e3o4z'>

                <tbody id='e3o4z'></tbody>

                • <i id='e3o4z'><tr id='e3o4z'><dt id='e3o4z'><q id='e3o4z'><span id='e3o4z'><b id='e3o4z'><form id='e3o4z'><ins id='e3o4z'></ins><ul id='e3o4z'></ul><sub id='e3o4z'></sub></form><legend id='e3o4z'></legend><bdo id='e3o4z'><pre id='e3o4z'><center id='e3o4z'></center></pre></bdo></b><th id='e3o4z'></th></span></q></dt></tr></i><div id='e3o4z'><tfoot id='e3o4z'></tfoot><dl id='e3o4z'><fieldset id='e3o4z'></fieldset></dl></div>
                • 本文介绍了AttributeError: 'list' 对象没有使用 Selenium 和 Python 的属性 'click'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在默认设置为季度"的页面上单击年度"按钮.有两个链接基本上被称为相同,除了一个有 data-ptype="Annual" 所以我尝试复制 xpath 以单击按钮(也尝试了其他选项,但没有一个有效).

                  I'd like to click the button 'Annual' at a page that is by default set on 'Quarterly'. There are two links that are basically called the same, except that one has data-ptype="Annual" so I tryed to copy the xpath to click the button (also tried other options but none did work).

                  但是,我得到 AttributeError: 'list' object has no attribute 'click'.我阅读了很多类似的帖子,但无法解决我的问题..所以我认为 javascript 事件必须以某种方式被调用/单击/执行.. idk 我卡住了

                  However, I get the AttributeError: 'list' object has no attribute 'click'. I read a lot of similar posts, but wasn't able to fix my problem.. so I assume that javascript event must be called/clicked/performed somehow differnt.. idk Im stuck

                  from selenium import webdriver
                  link = 'https://www.investing.com/equities/apple-computer-inc-balance-sheet'
                  
                  driver = webdriver.Firefox()
                  driver.get(link)
                  elm = driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()
                  

                  html 如下:

                  <a class="newBtn toggleButton LightGray" href="javascript:void(0);" data-type="rf-type-button" data-ptype="Annual" data-pid="6408" data-rtype="BAL">..</a>
                  

                  推荐答案

                  我仍然建议你使用 linkText 而不是 XPATH.这个 xpath 的原因: /html/body/div[5]/section/div[8]/div[1]/a[1] 非常绝对,如果有 可能会失败又一个 div 添加从 HTML 中删除.而更改链接文本的机会非常小.

                  I would still suggest you to go with linkText over XPATH. Reason this xpath : /html/body/div[5]/section/div[8]/div[1]/a[1] is quite absolute and can be failed if there is one more div added or removed from HTML. Whereas chances of changing the link Text is very minimal.

                  所以,而不是这个代码:

                  elm = driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()
                  

                  试试这个代码:

                  annual_link = driver.find_element_by_link_text('Annual')
                  annual_link.click()
                  

                  是的,@Druta 是对的,将 find_element 用于一个 Web 元素,将 find_elements 用于 Web 元素列表.显式等待总是好的.

                  and yes @Druta is right, use find_element for one web element and find_elements for list of web element. and it is always good to have explicit wait.

                  像这样创建显式等待的实例:

                  Create instance of explicit wait like this :

                  wait = WebDriverWait(driver,20)
                  

                  并像这样使用等待引用:

                  and use the wait reference like this :

                  wait.until(EC.elementToBeClickable(By.LINK_TEXT, 'Annual'))  
                  

                  更新:

                  from selenium import webdriver
                  link = 'https://www.investing.com/equities/apple-computer-inc-balance-sheet'
                  
                  driver = webdriver.Firefox()
                  driver.maximize_window()
                  wait = WebDriverWait(driver,40)
                  driver.get(link)  
                  
                  driver.execute_script("window.scrollTo(0, 200)") 
                  
                  wait.until(EC.element_to_be_clickable((By.LINK_TEXT, 'Annual')))
                  annual_link = driver.find_element_by_link_text('Annual')
                  annual_link.click()
                  print(annual_link.text)  
                  

                  确保导入这些:

                  from selenium.webdriver.common.keys import Keys
                  from selenium.webdriver.common.by import By
                  from selenium.webdriver.support.ui import WebDriverWait
                  from selenium.webdriver.support import expected_conditions as EC 
                  

                  这篇关于AttributeError: 'list' 对象没有使用 Selenium 和 Python 的属性 'click'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Ruby 编写的 Webdriver 测试中执行 JavaScript 下一篇:XMLHttpRequest:以 XML 和图像作为有效负载的多部分

                  相关文章

                  最新文章

                  1. <i id='GeDmm'><tr id='GeDmm'><dt id='GeDmm'><q id='GeDmm'><span id='GeDmm'><b id='GeDmm'><form id='GeDmm'><ins id='GeDmm'></ins><ul id='GeDmm'></ul><sub id='GeDmm'></sub></form><legend id='GeDmm'></legend><bdo id='GeDmm'><pre id='GeDmm'><center id='GeDmm'></center></pre></bdo></b><th id='GeDmm'></th></span></q></dt></tr></i><div id='GeDmm'><tfoot id='GeDmm'></tfoot><dl id='GeDmm'><fieldset id='GeDmm'></fieldset></dl></div>

                      <tfoot id='GeDmm'></tfoot>

                      <small id='GeDmm'></small><noframes id='GeDmm'>

                      <legend id='GeDmm'><style id='GeDmm'><dir id='GeDmm'><q id='GeDmm'></q></dir></style></legend>
                      • <bdo id='GeDmm'></bdo><ul id='GeDmm'></ul>