角拖& HTML5无法通过Selenium和Python删除 [英] Angular drag & drop with HTML5 not working through Selenium and Python

查看:107
本文介绍了角拖& HTML5无法通过Selenium和Python删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码不适用于演示AngularJS拖放列表:

My code does not working on demo AngularJS Drag and Drop list: http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple

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

driver = webdriver.Firefox()
driver.get("http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple")
time.sleep(2)
source_element = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[2]/ul/li[1]')
dest_element = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div/div[2]/ul/li[3]')

actions = ActionChains(driver)
actions.drag_and_drop(source_element, dest_element)
actions.perform()
time.sleep(10)
os.system("taskkill /im firefox.exe /f")

我尝试了许多解决方案,但是没有用.以我的观点,问题在于掉落"动作.

I try many solutions, but it is not working. By my opinion, problem is in "drop" action.

推荐答案

网页http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple上的元素是和,这里是观察结果:

The elements on the webpage http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple are elements. I took your code, made a couple of simple modifications and executed the drag_and_drop functionality through firefox and chrome and here are the observations:

  • 代码块:

  • Code Block:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple")
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h1[text()='Demo: Simple Lists']")))
driver.execute_script("return arguments[0].scrollIntoView(true);", element)
source_element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@dnd-list='list']/li[normalize-space()='Item A1']")))
dest_element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@dnd-list='list']/li[normalize-space()='Item B2']")))
ActionChains(driver).drag_and_drop(source_element, dest_element).perform()

  • 观察:文本为 A1项目的元素被成功 拖拽,但从未被删除.也可以使用 Chrome / ChromeDriver 重现此问题.

  • Observation: Element with text as Item A1 is successfully dragged but is never dropped. This issue can be reproduced using Chrome / ChromeDriver as well.

    浏览器快照:

    这是 Selenium 的一个已知问题,已在线程

    This is a known issue with Selenium and was discussed in details within the thread HTML5 Drag and Drop with Selenium Webdriver

    对于可行的解决方案,您可以遵循如何在Selenium Webdriver中模拟HTML5拖放?

    For a working solution you can follow the discussion in How to simulate HTML5 Drag and Drop in Selenium Webdriver?

    您可以在 chromedriver 问题列表通过chrome调试协议拖放无法正常工作

    You can find a detailed discussion in the chromedriver issue list HTML5 drag and drop is not working which is currently blocked by the chromium issue Drag and drop not working through chrome debug protocol

    这篇关于角拖& HTML5无法通过Selenium和Python删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆