2

在尝试使用 selenium webdriver 执行拖放时,会抛出以下回溯。

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'`

代码片段:

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()

甚至 click_and_hold 也会抛出同样的错误。感谢帮助。

4

0 回答 0