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

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

      1. Python.硒.拖放错误“AttributeError:move_to 需要 WebElement"

        时间:2023-07-05
          <tfoot id='WeGcY'></tfoot>

          1. <small id='WeGcY'></small><noframes id='WeGcY'>

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

                • <bdo id='WeGcY'></bdo><ul id='WeGcY'></ul>
                  本文介绍了Python.硒.拖放错误“AttributeError:move_to 需要 WebElement"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  请告诉我,我做错了什么?我尝试通过 Selenium 拖放,但每次遇到错误AttributeError: move_to requires a WebElement"

                  Tell me please, what am I doing wrong? I try to drag and drop through Selenium, but every time I come across an error "AttributeError: move_to requires a WebElement"

                  这是我的代码:

                  from selenium import webdriver
                  from selenium.webdriver.common.action_chains import ActionChains
                  
                  chromedriver = '/usr/local/bin/chromedriver'
                  
                  driver = webdriver.Chrome(chromedriver)
                  driver.get('http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html')
                  
                  source = driver.find_elements_by_xpath('//*[@id="box3"]')
                  target = driver.find_elements_by_xpath('//*[@id="box103"]')
                  
                  action = ActionChains(driver)
                  action.drag_and_drop(source, target).perform()
                  

                  我也试过了,像这样:

                  from selenium import webdriver
                  from selenium.webdriver.common.action_chains import ActionChains
                  
                  chromedriver = '/usr/local/bin/chromedriver'
                  
                  driver = webdriver.Chrome(chromedriver)
                  driver.get('http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html')
                  
                  source = driver.find_elements_by_xpath('//*[@id="box3"]')
                  target = driver.find_elements_by_xpath('//*[@id="box103"]')
                  ActionChains(driver).click_and_hold(source).move_to_element(target).release(target).perform()
                  

                  总是出现AttributeError: move_to requires a WebElement"

                  Traceback (most recent call last):
                    File "drag_and_drop_test.py", line 13, in <module>
                      ActionChains(driver).click_and_hold(source).move_to_element(target).release(target).perform()
                    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/action_chains.py", line 121, in click_and_hold
                      self.move_to_element(on_element)
                    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/action_chains.py", line 273, in move_to_element
                      self.w3c_actions.pointer_action.move_to(to_element)
                    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/actions/pointer_actions.py", line 42, in move_to
                      raise AttributeError("move_to requires a WebElement")
                  AttributeError: move_to requires a WebElement
                  

                  推荐答案

                  find_elements_by_xpath 返回 WebElement 的列表,drag_and_drop(以及其他方法)接受单个 WebElement.使用 find_element_by_xpath

                  find_elements_by_xpath returns a list of WebElements, drag_and_drop (and the other methods) accept a single WebElement. Use find_element_by_xpath

                  source = driver.find_element_by_xpath('//*[@id="box3"]')
                  target = driver.find_element_by_xpath('//*[@id="box103"]')
                  

                  这篇关于Python.硒.拖放错误“AttributeError:move_to 需要 WebElement"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Selenium/Python - 提交表单后提取动态生成的 HTML 下一篇:驱动程序信息:driver.version:ChromeDriver Chrome 使用 Selenium 和 Pyth

                  相关文章

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

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

                      <tfoot id='Aqwno'></tfoot>

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