无法执行拖放 python selenium
cannot perform drag-n-drop python selenium
我在 selenium 中创建了一个测试并在 python 中导出了它。测试包括将元素拖放到 div。当我 运行 python 中的测试无法执行拖放操作。我为此使用的代码是:
source_element = self.driver.find_elements_by_xpath("//*[contains(@id,
'plinkTest')]")
dest_element = self.driver.find_elements_by_xpath("//*
[@id='tools_dep_jstree_id']")
actions = ActionChains(self.driver)
actions.move_to_element(source_element).click_and_hold().perform()
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).perform()
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).release().perform()
我收到的错误是 "move_to requires a web element"。
find_elements_by_xpath()
将 returns 作为 list 而不是 WebElement.
从 find_elements_by_xpath()
更改以下行
source_element = self.driver.find_elements_by_xpath("//*[contains(@id,
'plinkTest')]")
dest_element = self.driver.find_elements_by_xpath("//*
[@id='tools_dep_jstree_id']")
到find_element_by_xpath()
source_element = self.driver.find_element_by_xpath("//*[contains(@id,
'plinkTest')]")
dest_element = self.driver.find_element_by_xpath("//*
[@id='tools_dep_jstree_id']")
问题是使用 find_elements_by_xpath 而不是 find_element_by_xpath(第一个返回列表,只是拼写错误)并且只能通过使用 [=15= 找到源元素] 文字:
source_element = self.driver.find_element_by_partial_link_text('plink')
dest_element = self.driver.find_element_by_xpath("//*[@id='tools_dep_jstree_id']/ul")
actions = ActionChains(self.driver)
actions.move_to_element(source_element).click_and_hold().perform()
time.sleep(2)
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).perform()
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).release().perform()
我在 selenium 中创建了一个测试并在 python 中导出了它。测试包括将元素拖放到 div。当我 运行 python 中的测试无法执行拖放操作。我为此使用的代码是:
source_element = self.driver.find_elements_by_xpath("//*[contains(@id,
'plinkTest')]")
dest_element = self.driver.find_elements_by_xpath("//*
[@id='tools_dep_jstree_id']")
actions = ActionChains(self.driver)
actions.move_to_element(source_element).click_and_hold().perform()
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).perform()
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).release().perform()
我收到的错误是 "move_to requires a web element"。
find_elements_by_xpath()
将 returns 作为 list 而不是 WebElement.
从 find_elements_by_xpath()
更改以下行 source_element = self.driver.find_elements_by_xpath("//*[contains(@id,
'plinkTest')]")
dest_element = self.driver.find_elements_by_xpath("//*
[@id='tools_dep_jstree_id']")
到find_element_by_xpath()
source_element = self.driver.find_element_by_xpath("//*[contains(@id,
'plinkTest')]")
dest_element = self.driver.find_element_by_xpath("//*
[@id='tools_dep_jstree_id']")
问题是使用 find_elements_by_xpath 而不是 find_element_by_xpath(第一个返回列表,只是拼写错误)并且只能通过使用 [=15= 找到源元素] 文字:
source_element = self.driver.find_element_by_partial_link_text('plink')
dest_element = self.driver.find_element_by_xpath("//*[@id='tools_dep_jstree_id']/ul")
actions = ActionChains(self.driver)
actions.move_to_element(source_element).click_and_hold().perform()
time.sleep(2)
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).perform()
actions = ActionChains(self.driver)
actions.move_to_element(dest_element).release().perform()