执行操作链的方法不起作用

时间:2016-01-22 13:16:16

标签: python selenium

我有一个案例需要使用Selenium webdriver和Python拖放元素。

我尝试使用Selenium的try { $dbh = new PDO('mysql:host=127.0.0.1;dbname=PHP_PDO', "root", "root", array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); } catch(PDOException $e) { die("FATAL ERROR OCCURED"); } $stmt = $dbh->prepare("SELECT realname FROM users WHERE name = :name" ); $stmt->bindParam(":name", $name); $name = "mivuckovaca"; // NOT IN DATA BASE 类,代码有点像这样:

ActionChains

我得到的错误是:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

source = ("//span[text()='user1']", Selector.XPATH)
target = ("//span[text()='user2']", Selector.XPATH)
acs = ActionChains(webdriver_api)
change = acs.drag_and_drop(source, target)
change.perform()

1 个答案:

答案 0 :(得分:0)

sourcetarget需要WebElement个实例:

source = webdriver_api.find_element_by_xpath("//span[text()='user1']")
target = webdriver_api.find_element_by_xpath("//span[text()='user2']")

acs = ActionChains(webdriver_api)
change = acs.drag_and_drop(source, target)
change.perform()