Selenium-DragAndDropBy在Mac OS Hi Sierra的Safari 12.1上不起作用

时间:2019-04-09 09:57:27

标签: java selenium selenium-webdriver safari

我试图在Mac Os Hi Sierra上的Safari 12.1上拖放对象。

它拖动对象,移动到指定位置,但不会释放对象。

我执行了下面提到的代码行,但是它们都具有相同的效果:

actionTest.dragAndDropBy(dragMe,
xCoOrdinate,yCoOrdinate).build().perform();

actionTest.dragAndDropBy(dragMe,
xCoOrdinate,yCoOrdinate).release().build().perform();

如果需要设置任何浏览器功能,请提出建议。

使用的测试网址为: https://www.bryntum.com/examples/scheduler/animations/

Please see "Import Meeting" in the screenshot.

1 个答案:

答案 0 :(得分:0)

拖放语法。 Actions类有两个支持拖放的方法。让我们研究它们-

Actions.dragAndDrop(Sourcelocator, Destinationlocator)

在某些应用程序中,我们可能会遇到将项目从一个位置自动拖放到另一位置的自动化情况。我们无法使用基本元素来实现这些目标。 Selenium提供了一个“ Actions ”类来处理这种情况。我们克服了这种情况,例如使用Actions类进行拖放。

Action Class in Selenium

dragAndDrop 方法中,我们传递了两个参数-

第一个参数“ Sourcelocator” 是我们需要拖动的元素。

第二个参数“目标定位器” 是我们需要在其上放置第一个元素的元素

Actions.dragAndDropBy(Sourcelocator, x-axis pixel of Destinationlocator, y-axis pixel of Destinationlocator)

dragAndDropBy方法,我们传递了3个参数-

  1. 第一个参数“ Sourcelocator”是我们需要拖动的元素。
  2. 第二个参数是我们要在其上放置第一个元素的第二个元素的x轴像素值。
  3. 第三个参数是我们要在其上放置第一个元素的第二个元素的y轴像素值。

您还可以从this网站上获取更多信息。

尝试一下:-

    WebDriver driver= new FirefoxDriver();
    driver.get("https://www.bryntum.com/examples/scheduler/animations/");
    //driver.get("https://demoqa.com/droppable/");
    WebElement From=driver.findElement(By.xpath("//*[@id=\"b-scheduler-8-1-1-x\"]/div"));   

    WebElement To=driver.findElement(By.xpath("//*[@id=\"b-subgrid-14\"]/div[2]/div")); 
    Actions act=new Actions(driver);                    

    //Dragged and dropped.      
         act.dragAndDrop(From, To).build().perform();   

希望它会为您服务。

请不要通过this链接访问此类元素。