博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Selenium] WebDriver 操作 HTML5 中的 drag/drop
阅读量:7108 次
发布时间:2019-06-28

本文共 1384 字,大约阅读时间需要 4 分钟。

以 jQuery UI 官方网站元素测试,地址:http://jqueryui.com/draggable/

示例:

package com.learningselenium.html5;

 

import java.util.NoSuchElementException;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

 

public class testActionDragAndDrop{

  WebDriver driver = new FirefoxDriver();

 

  private boolean isElementPresent(By by){

    try{

      driver.findElement(by);

      return true;

    }catch(NoSuchElemention e){

      return false;

    }

  }

 

  @Before

  public void setUp() throws Exception{

    driver.get("http://jqueryui.com/draggable/");

  }

 

  @Test

  public void testActionDragAndDrop() throws Exception{

    //switchto().frame 来切换焦点到iframe.demo-frame

    driver.switchTo().frame(driver.findElement(By.className("demo-frame")));

    Thread.sleep(3000);

    if(! isElementPresent(By.xpath("//div[@id='draggable']"))){

      Trhead.sleep(3000);

    }

    WebElement draggable = driver.findElement(By.xpath("//div[@id='draggable']"));

    new Actions(driver).dragAndDropBy(draggable,200,10).build().perform();

    Thread.sleep(10000);

  }

 

  @After 

  public void tearDown() throws Exception{

    driver.quit();

  }

}

 

转载于:https://www.cnblogs.com/feifeidxl/p/4554711.html

你可能感兴趣的文章
${oid?c}的使用
查看>>
12306多种手段反击浏览器厂商“见招拆招”
查看>>
iOS 推送,服务器。证书。
查看>>
白话学习MVC(三)页面周期二
查看>>
POJ 1611 The Suspects (并查集,简单)
查看>>
embOS实时操作系统 - 概览
查看>>
进程函数一步步理解Linux进程(2)--进程编程进程函数
查看>>
Oracle执行计划详解
查看>>
默认值约束一些工作和学习中经常用到的SQL语句
查看>>
优化网站设计(四):对资源启用压缩
查看>>
如何从Android so中提取URL
查看>>
function删除js操作cookie
查看>>
200个最常见的JAVA面试问题(附答案)
查看>>
C++ 生成三次贝塞尔曲线
查看>>
【程序5】 条件运算符的嵌套
查看>>
POJ 3259 Wormholes
查看>>
Codeforces Perfect Pair (JAVA)
查看>>
自定义Web控件写事件
查看>>
The document has been modified outside of Code Composer. Would you like to reload the file
查看>>
C语言位操作--逻辑运算符组合
查看>>