/** * Drag and drop an element on top of other element * @param targetElement the target element */ @Override @PublicAtsApi public void dragAndDropTo( HtmlElement targetElement ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); WebElement source = HiddenHtmlElementLocator.findElement(this); WebElement target = HiddenHtmlElementLocator.findElement(targetElement); Actions actionBuilder = new Actions(htmlUnitDriver); Action dragAndDropAction = actionBuilder.clickAndHold(source) .moveToElement(target, 1, 1) .release(target) .build(); dragAndDropAction.perform(); // drops the source element in the middle of the target, which in some cases is not doing drop on the right place // new Actions( htmlUnitDriver ).dragAndDrop( source, target ).perform(); }
/** * Drag and drop an element on top of other element * @param targetElement the target element */ @Override @PublicAtsApi public void dragAndDropTo( HtmlElement targetElement ) { new RealHtmlElementState(this).waitToBecomeExisting(); WebElement source = RealHtmlElementLocator.findElement(this); WebElement target = RealHtmlElementLocator.findElement(targetElement); Actions actionBuilder = new Actions(webDriver); Action dragAndDropAction = actionBuilder.clickAndHold(source) .moveToElement(target, 1, 1) .release(target) .build(); dragAndDropAction.perform(); // drops the source element in the middle of the target, which in some cases is not doing drop on the right place // new Actions( webDriver ).dragAndDrop( source, target ).perform(); }
@Test public void dragAndDropFirefox() throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.get("http://www.w3schools.com/html/html5_draganddrop.asp"); WebElement source = driver.findElement(id("drag1")); System.out.println(source.getAttribute("src")); WebElement target = driver.findElement(id("div2")); System.out.println(target.getTagName() + "=" + target.toString()); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(source) .moveToElement(target) .release(source) .build(); dragAndDrop.perform(); }
@Test public void dragAndDropChrome() throws InterruptedException { WebDriver driver = new ChromeDriver(); driver.get("http://www.w3schools.com/html/html5_draganddrop.asp"); WebElement source = driver.findElement(id("drag1")); System.out.println(source.getAttribute("src")); WebElement target = driver.findElement(id("div2")); System.out.println(target.getTagName() + "=" + target.toString()); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(source) .moveToElement(target) .release(source) .build(); dragAndDrop.perform(); }
@Test public void dragAndDropSafari() throws InterruptedException { WebDriver driver = new SafariDriver(); driver.get("http://www.w3schools.com/html/html5_draganddrop.asp"); WebElement source = driver.findElement(id("drag1")); System.out.println(source.getAttribute("src")); WebElement target = driver.findElement(id("div2")); System.out.println(target.getTagName() + "=" + target.toString()); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(source) .moveToElement(target) .release(source) .build(); dragAndDrop.perform(); }
@Test public void testCanFlickVerticallyFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 4200); WebElement toFlick = driver().findElement(By.id("imagestart")); Action flick = getBuilder(driver()).flick(toFlick, 0, -600, FlickAction.SPEED_NORMAL).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Expected y < 4000, but got: " + y, y < 4000); }
@Test public void testCanFlickVerticallyFastFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link4")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 8700); WebElement toFlick = driver().findElement(By.id("imagestart")); Action flick = getBuilder(driver()).flick(toFlick, 0, -600, FlickAction.SPEED_FAST).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Expected y < 8700, but got: " + y, y < 8700); }
@Test public void testCanFlickVertically() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 4200); Action flick = getBuilder(driver()).flick(0, 750).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Got: " + y, y < 4200); }
@Test public void testCanFlickVerticallyFast() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link4")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 8700); Action flick = getBuilder(driver()).flick(0, 1500).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Got: " + y, y < 4000); }
@Test public void testCanScrollVerticallyFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue("Expected y > 4200, but got y = " + y, y > 4200); WebElement toScroll = driver().findElement(By.id("imagestart")); Action scroll = getBuilder(driver()).scroll(toScroll, 0, -800).build(); scroll.perform(); y = link.getLocation().y; // After scrolling, the location of the element should change accordingly. assertTrue("Expected y < 3500, but got y = " + y, y < 3500); }
@Test public void testCanScrollHorizontallyFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link1")); int x = link.getLocation().x; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue("Expected x > 1500, but got x = " + x, x > 1500); WebElement toScroll = driver().findElement(By.id("imagestart")); Action scroll = getBuilder(driver()).scroll(toScroll, -1000, 0).build(); scroll.perform(); x = link.getLocation().x; // After scrolling, the location of the element should change accordingly. assertTrue("Expected x < 3000, but got x = " + x, x < 3000); }
@Test public void testCanScrollVertically() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue(y > 4200); Action scrollDown = getBuilder(driver()).scroll(0, 800).build(); scrollDown.perform(); y = link.getLocation().y; // After scrolling, the location of the element should change accordingly. assertTrue(y < 3500); }
@Test public void testCanScrollHorizontally() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link1")); int x = link.getLocation().x; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue("Expected x > 1500, but got x = " + x, x > 1500); Action scrollDown = getBuilder(driver()).scroll(400, 0).build(); scrollDown.perform(); x = link.getLocation().y; // After scrolling, the location of the element should change accordingly. assertTrue("Expected x < 1500, but got x = " + x, x < 1500); }
public void dragDrop(WebElement from, WebElement to) { Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(from) .moveToElement(to) .release(to) .build(); dragAndDrop.perform(); }
@Test public void test() throws InterruptedException { driver.get("http://szimek.github.io/signature_pad/"); WebElement canvas = driver.findElement(By.tagName("canvas")); Action action = new Actions(driver).click(canvas) .moveToElement(canvas, 8, 8).clickAndHold(canvas) .moveByOffset(120, 120).moveByOffset(-120, 120) .moveByOffset(-120, -120).moveByOffset(8, 8).release(canvas) .build(); action.perform(); Thread.sleep(5000); }
@Test() //dependsOnMethods = "displayListOf") public void openFirstListElement() { WebElement listRootPanel = waitTillElementContains("gwt-debug-listRootPanel", defaultTimeout, "Anzeige Eintrag"); if(countAfterListOpened > 0) { // RootPanel/div tabindex=0 /div style pixel/div class XMOC /div class XG0B /div class XB-B /table cl. XNOC /tbody nr. 2 /tr/td/div WebElement div = listRootPanel.findElement(By.xpath("./*[position()=1]/*[position()=2]/*[position()=1]/*[position()=2]/*[position()=1]/*[position()=1]/*[position()=2]/*/*")); // WebElement tr = listRootPanel.findElement(By.xpath("./*[position()=1]/*[position()=2]/*[position()=1]/*[position()=2]/*[position()=1]/*[position()=1]/*[position()=2]/*")); // WebElement td = listRootPanel.findElement(By.xpath("./*[position()=1]/*[position()=2]/*[position()=1]/*[position()=2]/*[position()=1]/*[position()=1]/*[position()=2]/*/*")); Actions actions = new Actions(webDriver); actions.doubleClick(div); Action dblClick = actions.build(); dblClick.perform(); // Action dblClick = actions.doubleClick(div); // dblClick.build().perform(); // // actions.click(div); // actions.click(div); // actions.doubleClick(div); // actions.doubleClick(td); // actions.doubleClick(tr); } else System.out.println("could not open element, since the list was empty!"); }
/** * A convenience method that performs click at the location of the source element * * @param xOffset - horizontal move offset. * @param yOffset - vertical move offset. * @return Parent instance */ public ParentPanel clickBy(int xOffset, int yOffset) { doJAction(format("click element: horizontal move offset- %dpx; vertical move offset- %dpx", xOffset, yOffset), () -> { Actions builder = new Actions(getDriver()); Action click = builder.moveToElement(getWebElement(), xOffset, yOffset).click().build(); click.perform(); }); return parent; }
@SuppressWarnings("unchecked") @Override public T doubleClick() { WebDriver driver = WiseContext.getDriver(); Action action = new Actions(driver).doubleClick(this.getWrappedElement()).build(); action.perform(); return (T) this; }
public static void customClick(WebDriver webDriver, WebElement webElement) { Actions action = new Actions(webDriver); Actions actionMoveTo = action.moveToElement(webElement); Action buildActionMoveTo = actionMoveTo.build(); buildActionMoveTo.perform(); WebDriverWait wait = new WebDriverWait(webDriver, 30); WebElement element = wait.until( ExpectedConditions.elementToBeClickable(webElement)); element.click(); }
public static void dataokeLoginTest()throws Exception{ WebDriver driver = initChromeDriver(); driver.manage().window().maximize(); driver.get("http://www.dataoke.com/login"); JavascriptExecutor js = (JavascriptExecutor) driver; boolean flag = doesWebElementExist(driver, By.id("nc_1__scale_text")); if(flag){ System.out.println("拖动存在>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); // Actions action = new Actions(driver); //获取滑动滑块的标签元素 WebElement source = driver.findElement(By.id("nc_1__scale_text")); //确保每次拖动的像素不同,故而使用随机数 //action.clickAndHold(source).moveByOffset(100, 0); //Thread.sleep(1000); //确保每次拖动的像素不同,故而使用随机数 //action.clickAndHold(source).moveByOffset(200, 0); //Thread.sleep(1000); //确保每次拖动的像素不同,故而使用随机数 action.clickAndHold(source).moveByOffset(300, 0); Thread.sleep(1000); //拖动完释放鼠标 action.moveToElement(source).release(); Thread.sleep(1000); //组织完这些一系列的步骤,然后开始真实执行操作 Action actions = action.build(); actions.perform(); Thread.sleep(3000); System.out.println("拖动完成>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); } }
/** * This method performs the slider change action of the web interface. * @param slider : The element of the slider to be changed. * @param val : Value to be set. */ private void moveSlider(WebElement slider, int val) { Actions move = new Actions(driver); Action action = move.dragAndDropBy(slider, 0, val).build(); action.perform(); }
@Override public ArrayList<Action> getActionQueue() { return actionsQueue; }
private void singleTapOnElement(String elementId) { WebElement toSingleTap = driver().findElement(By.id(elementId)); Action singleTap = getBuilder(driver()).singleTap(toSingleTap).build(); singleTap.perform(); }
/** * Gets the action queue if it has one. * @return Actions in an array list to cycle through. */ public ArrayList<Action> getActionQueue();