Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Selenium Web驱动程序(Python)拖放元素_Python_Selenium_Drag And Drop_Webdriver_Drag - Fatal编程技术网

无法使用Selenium Web驱动程序(Python)拖放元素

无法使用Selenium Web驱动程序(Python)拖放元素,python,selenium,drag-and-drop,webdriver,drag,Python,Selenium,Drag And Drop,Webdriver,Drag,在尝试使用SeleniumWebDriver执行拖放时,将抛出以下回溯 File "/Library/Python/2.7/site-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/common/action_chains.py", line 44, in perform action() File "/Library/Python/2.7/site-packages/selenium-2.15.0-py2.7.egg/se

在尝试使用SeleniumWebDriver执行拖放时,将抛出以下回溯

File
"/Library/Python/2.7/site-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/common/action_chains.py",
line 44, in perform
    action()   File "/Library/Python/2.7/site-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/common/action_chains.py",
line 201, in <lambda>
    self._driver.execute(Command.MOVE_TO, {'element': to_element.id})) AttributeError: 'str' object has no attribute 'id'`
文件
“/Library/Python/2.7/site packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/common/action_chains.py”,
执行中的第44行
action()文件“/Library/Python/2.7/site packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/common/action_chains.py”,
第201行,在
self._driver.execute(Command.MOVE_TO,{'element':TO_element.id}))AttributeError:'str'对象没有属性'id'`
代码段:

from selenium import webdriver
from selenium.webdriver import ActionChains
driver = webdriver.Firefox()
ac = ActionChains()
source = driver.get_element_by_xpath(<xpath>)
target = driver.get_element_by_xpath(<xpath>)
ac.drag_and_drop(source, target).perfrom()
从selenium导入webdriver
从selenium.webdriver导入操作链
driver=webdriver.Firefox()
ac=动作链()
source=驱动程序。通过xpath()获取元素
target=驱动程序。通过xpath()获取元素
ac.drag_和drop(源、目标).perfrom()

即使单击和按住也会抛出相同的错误。感谢您的帮助。

您是否仔细检查了两个XPath是否能够唯一地识别屏幕上的web元素?是的。XPath是唯一标识元素。不知怎的,上面提到的代码现在运行正常。@sans09您找到解决方案了吗?