为什么我的硒在任何意义上都无法拖放

时间:2017-06-28 06:09:11

标签: python selenium selenium-chromedriver

enter image description

我正在进行自动化测试,我想将左侧文档“高级元素”拖动到图片右侧的画布单元格中。但是我使用的命令如drag_and_drop,单击并按住。文档永远不会被拖动到画布单元格。

    drag_1 = gt("//button[@class='mat-icon-button']")
    drag_a = gt("//div[@class='dynamic-container']")
    action.drag_and_drop(drag_1, drag_a).perform()

这是我将drag_1拖到drag_a的代码,但它无效。

1 个答案:

答案 0 :(得分:0)

查看this answer

总结它所说的内容(C#):

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(someElement)
   .moveToElement(otherElement)
   .release(otherElement)
   .build();

dragAndDrop.perform();

在Python中,这将转换为

click_and_drag = ActionChains(driver)
click_and_drag.click_and_hold(someElement)
click_and_drag.move_to_element(otherElement)
click_and_drag.release(otherElement)
click_and_drag.perform()