簡體   English   中英

無法使用 Selenium 單擊項目 - Python

[英]Can't click item with Selenium - Python

所以我有這個運行良好的腳本,然后停止工作。 當我運行腳本並出現此錯誤時,該項目沒有被點擊。

Traceback (most recent call last):
 File "/Users/6ko/Desktop/CodePython/katas/kata3.py", line 47, in <module>
   actions.perform()
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/common/action_chains.py", line 80, in perform
   self.w3c_actions.perform()
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/common/actions/action_builder.py", line 76, in perform
   self.driver.execute(Command.W3C_ACTIONS, enc)
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
   self.error_handler.check_response(response)
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
   raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds 

這是我的代碼:


edu = driver.find_element_by_id("118735")
ActionChains(driver).click(edu).perform()

這是網站的元素代碼:


    <div class="tnt-item" style="cursor: pointer; pointer-events: auto;" id="118735">
                  <div class="song" style="opacity: 1;">
                    <div class="position">17</div>
                    <div class="song-cover" style="position:relative;"><img class="img-fluid" src="/upload/album/00000036404.jpg"></div>
                    <div class="song-info">
                      <div class="song-name">Love You Better</div>
                      <div class="song-artists"><span title="Edu Monteiro">Edu Monteiro</span></div>
                      <div class="tnt-listen-music">
                        <div class="audioPlayer sm2-bar-ui small">
                          <div class="bd sm2-main-controls">
                            <div class="sm2-inline-element sm2-button-element">
                              <div class="sm2-button-bd"><a class="sm2-inline-button play-pause tm-30sec-listen" href="#play" id="TNT">
                            Play / pause</a></div>
                            </div>
                            <div class="sm2-inline-element sm2-inline-status">
                              <div class="sm2-playlist">
                                <div class="sm2-playlist-target"><ul class="sm2-playlist-bd"><li></li></ul></div>
                              </div>
                              <div class="sm2-progress">
                                <div class="sm2-progress-bd">
                                  <div class="sm2-progress-track">
                                    <div class="sm2-progress-bar"></div>
                                    <div class="sm2-progress-ball">
                                      <div class="icon-overlay"></div>
                                    </div>
                                  </div>
                                </div>
                                <div class="sm2-inline-time">0:00</div>
                                <div class="sm2-inline-duration">0:00</div>
                              </div>
                            </div>
                          </div>
                          <div class="bd sm2-playlist-drawer sm2-element">
                            <div class="sm2-playlist-wrapper">
                              <ul class="sm2-playlist-bd">
                                <li class="selected"><a id="" class="norewrite exclude button-exclude inline-exclude audiofile" style="font-size:0px;" isexclusiveplay="true" isclip="true" href="9x4h6qd1-48y7-5fxt-q5ll-dknvbm4r42f5.mp4"></a></li>
                              </ul>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="song-check"><input type="checkbox" name="tnt-vote" class="tnt-vote" style="pointer-events:none;"></div>
                  </div>
                </div>

你能幫我嗎? 已經搜索過類似的問題,但找不到解決我的問題的方法。 非常感謝您的參與!

(劇本是給一首音樂投票,這是網站https://radicomercial.iol.pt/programas/tnt

您是否嘗試先移動到元素?

edu = driver.find_element_by_id("118735")
try:
    ActionChains(driver).move_to_element(edu).perform()
except Exception as e:
    print("Exception :", str(e))
#edu.click() selenium.common.exceptions.ElementClickInterceptedException
driver.execute_script("arguments[0].click();", edu)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM