How to use Interface Coordinates class of org.openqa.selenium.interactions package

Best Selenium code snippet using org.openqa.selenium.interactions.Interface Coordinates

Source:MouseElementActions.java Github

copy

Full Screen

1package org.fluentlenium.core.action;2import org.fluentlenium.core.domain.FluentWebElement;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.interactions.Coordinates;6import org.openqa.selenium.interactions.HasInputDevices;7import org.openqa.selenium.interactions.Mouse;8/**9 * Element specific mouse control interface.10 */11public class MouseElementActions {12 private final WebDriver driver;13 private final WebElement element;14 /**15 * Creates a new mouse element actions.16 *17 * @param driver selenium driver18 * @param element selenium element19 */20 public MouseElementActions(WebDriver driver, WebElement element) {21 this.driver = driver;22 this.element = element;23 }24 /**25 * Creates a new mouse element actions.26 *27 * @param driver selenium driver28 * @param fluentWebElement FluentWebElement29 */30 public MouseElementActions(WebDriver driver, FluentWebElement fluentWebElement) {31 this.driver = driver;32 this.element = fluentWebElement.getElement();33 }34 private org.openqa.selenium.interactions.Actions actions() {35 return new org.openqa.selenium.interactions.Actions(driver);36 }37 /**38 * Basic mouse operations39 *40 * @return low level interface to control the mouse41 * @deprecated Use the following mapping for updating your code:42 * <p>43 * {@link Mouse#click(Coordinates)} to {@link MouseElementActions#click()}44 * <p>45 * {@link Mouse#doubleClick(Coordinates)} to {@link MouseElementActions#doubleClick()}46 * <p>47 * {@link Mouse#mouseDown(Coordinates)} to {@link MouseElementActions#moveToElement()}48 * then {@link MouseElementActions#clickAndHold()}49 * <p>50 * {@link Mouse#mouseUp(Coordinates)} to {@link MouseElementActions#release()}51 * <p>52 * {@link Mouse#mouseMove(Coordinates)} to {@link MouseElementActions#moveToElement()}53 * <p>54 * {@link Mouse#mouseMove(Coordinates, long, long)} to {@link MouseElementActions#moveToElement(int, int)}55 * <p>56 * {@link Mouse#contextClick(Coordinates)} to {@link MouseElementActions#contextClick()}57 */58 @Deprecated59 public Mouse basic() {60 return ((HasInputDevices) driver).getMouse();61 }62 /**63 * Clicks (without releasing) in the middle of the given element. This is equivalent to:64 * <i>Actions.moveToElement(onElement).clickAndHold()</i>65 *66 * @return this object reference to chain calls67 * @see org.openqa.selenium.interactions.Actions#clickAndHold(WebElement)68 */69 public MouseElementActions clickAndHold() {70 actions().clickAndHold(element).perform();71 return this;72 }73 /**74 * Releases the depressed left mouse button, in the middle of the given element.75 * This is equivalent to:76 * <i>Actions.moveToElement(onElement).release()</i>77 * <p>78 * Invoking this action without invoking {@link #clickAndHold()} first will result in79 * undefined behaviour.80 *81 * @return this object reference to chain calls82 * @see org.openqa.selenium.interactions.Actions#release(WebElement)83 */84 public MouseElementActions release() {85 actions().release(element).perform();86 return this;87 }88 /**89 * Clicks in the middle of the given element. Equivalent to:90 * <i>Actions.moveToElement(onElement).click()</i>91 *92 * @return this object reference to chain calls93 * @see org.openqa.selenium.interactions.Actions#click(WebElement)94 */95 public MouseElementActions click() {96 actions().click(element).perform();97 return this;98 }99 /**100 * Performs a double-click at middle of the given element. Equivalent to:101 * <i>Actions.moveToElement(element).doubleClick()</i>102 *103 * @return this object reference to chain calls104 * @see org.openqa.selenium.interactions.Actions#doubleClick(WebElement)105 */106 public MouseElementActions doubleClick() {107 actions().doubleClick(element).perform();108 return this;109 }110 /**111 * Moves the mouse to the middle of the element. The element is scrolled into view and its112 * location is calculated using getBoundingClientRect.113 *114 * @return this object reference to chain calls115 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement)116 */117 public MouseElementActions moveToElement() {118 actions().moveToElement(element).perform();119 return this;120 }121 /**122 * Moves the mouse to the middle of the target element. The element is scrolled into view and its123 * location is calculated using getBoundingClientRect.124 *125 * @param target element to move to and release the mouse at.126 * @return this object reference to chain calls127 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement)128 */129 public MouseElementActions moveToElement(WebElement target) {130 actions().moveToElement(target).perform();131 return this;132 }133 /**134 * Moves the mouse to an offset from the top-left corner of the element.135 * The element is scrolled into view and its location is calculated using getBoundingClientRect.136 *137 * @param xOffset Offset from the top-left corner. A negative value means coordinates left from138 * the element139 * @param yOffset Offset from the top-left corner. A negative value means coordinates above140 * the element141 * @return this object reference to chain calls142 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement, int, int)143 */144 public MouseElementActions moveToElement(int xOffset, int yOffset) {145 actions().moveToElement(element, xOffset, yOffset).perform();146 return this;147 }148 /**149 * Moves the mouse to an offset from the top-left corner of the target element.150 * The element is scrolled into view and its location is calculated using getBoundingClientRect.151 *152 * @param target element to move to and release the mouse at.153 * @param xOffset Offset from the top-left corner. A negative value means coordinates left from154 * the element155 * @param yOffset Offset from the top-left corner. A negative value means coordinates above156 * the element157 * @return this object reference to chain calls158 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement, int, int)159 */160 public MouseElementActions moveToElement(WebElement target, int xOffset, int yOffset) {161 actions().moveToElement(target, xOffset, yOffset).perform();162 return this;163 }164 /**165 * Performs a context-click at middle of the given element. First performs a mouseMove166 * to the location of the element.167 *168 * @return this object reference to chain calls169 * @see org.openqa.selenium.interactions.Actions#contextClick(WebElement)170 */171 public MouseElementActions contextClick() {172 actions().contextClick(element).perform();173 return this;174 }175 /**176 * A convenience method that performs click-and-hold at the location of the source element,177 * moves to the location of this element (target), then releases the mouse.178 *179 * @param source element to emulate button down at180 * @return this object reference to chain calls181 * @see org.openqa.selenium.interactions.Actions#dragAndDrop(WebElement, WebElement)182 */183 public MouseElementActions dragAndDropFrom(WebElement source) {184 actions().dragAndDrop(source, element).perform();185 return this;186 }187 /**188 * A convenience method that performs click-and-hold at the location of this element (source),189 * moves to the location of the target element, then releases the mouse.190 *191 * @param target element to move to and release the mouse at.192 * @return this object reference to chain calls193 * @see org.openqa.selenium.interactions.Actions#dragAndDrop(WebElement, WebElement)194 */195 public MouseElementActions dragAndDropTo(WebElement target) {196 actions().dragAndDrop(element, target).perform();197 return this;198 }199 /**200 * A convenience method that performs click-and-hold at the location of this element,201 * moves by a given offset, then releases the mouse.202 *203 * @param xOffset horizontal move offset.204 * @param yOffset vertical move offset.205 * @return this object reference to chain calls206 * @see org.openqa.selenium.interactions.Actions#dragAndDropBy(WebElement, int, int)207 */208 public MouseElementActions dragAndDropBy(int xOffset, int yOffset) {209 actions().dragAndDropBy(element, xOffset, yOffset).perform();210 return this;211 }212 /**213 * A convenience method that performs click-and-hold at the location of this element,214 * moves by a given offset of target element, then releases the mouse.215 *216 * This Method is not available in pure Selenium217 *218 * @param target element to move to and release the mouse at.219 * @param xOffset horizontal move offset.220 * @param yOffset vertical move offset.221 * @return this object reference to chain calls222 * @see org.openqa.selenium.interactions.Actions#dragAndDropBy(WebElement, int, int)223 */224 public MouseElementActions dragAndDropByWithTargetOffset(WebElement target, int xOffset, int yOffset) {225 actions().clickAndHold(element).moveToElement(target, xOffset, yOffset).release().perform();226 return this;227 }228}...

Full Screen

Full Screen

Source:MouseActions.java Github

copy

Full Screen

1package org.fluentlenium.core.action;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.interactions.Coordinates;4import org.openqa.selenium.interactions.HasInputDevices;5import org.openqa.selenium.interactions.Mouse;6/**7 * Execute actions with the mouse.8 */9public class MouseActions {10 private final WebDriver driver;11 /**12 * Creates a new mouse actions.13 *14 * @param driver driver15 */16 public MouseActions(WebDriver driver) {17 this.driver = driver;18 }19 /**20 * Get the actions object.21 *22 * @return actions object23 */24 protected org.openqa.selenium.interactions.Actions actions() {25 return new org.openqa.selenium.interactions.Actions(driver);26 }27 /**28 * Basic mouse operations29 *30 * @return low level interface to control the mouse31 * @deprecated Use the following mapping for updating your code:32 * <p>33 * {@link Mouse#click(Coordinates)} to {@link MouseElementActions#click()}34 * <p>35 * {@link Mouse#doubleClick(Coordinates)} to {@link MouseElementActions#doubleClick()}36 * <p>37 * {@link Mouse#mouseDown(Coordinates)} to {@link MouseElementActions#moveToElement()}38 * then {@link MouseElementActions#clickAndHold()}39 * <p>40 * {@link Mouse#mouseUp(Coordinates)} to {@link MouseElementActions#release()}41 * <p>42 * {@link Mouse#mouseMove(Coordinates)} to {@link MouseElementActions#moveToElement()}43 * <p>44 * {@link Mouse#mouseMove(Coordinates, long, long)} to {@link MouseElementActions#moveToElement(int, int)}45 * <p>46 * {@link Mouse#contextClick(Coordinates)} to {@link MouseElementActions#contextClick()}47 */48 @Deprecated49 public Mouse basic() {50 return ((HasInputDevices) driver).getMouse();51 }52 /**53 * Clicks (without releasing) at the current mouse location.54 *55 * @return this object reference to chain calls56 * @see org.openqa.selenium.interactions.Actions#clickAndHold()57 */58 public MouseActions clickAndHold() {59 actions().clickAndHold().perform();60 return this;61 }62 /**63 * Releases the depressed left mouse button at the current mouse location.64 *65 * @return this object reference to chain calls66 * @see org.openqa.selenium.interactions.Actions#release()67 */68 public MouseActions release() {69 actions().release().perform();70 return this;71 }72 /**73 * Clicks at the current mouse location. Useful when combined with74 *75 * @return this object reference to chain calls76 * @see org.openqa.selenium.interactions.Actions#click()77 */78 public MouseActions click() {79 actions().click().perform();80 return this;81 }82 /**83 * Performs a double-click at the current mouse location.84 *85 * @return this object reference to chain calls86 */87 public MouseActions doubleClick() {88 actions().doubleClick().perform();89 return this;90 }91 /**92 * Performs a context-click at the current mouse location.93 *94 * @return this object reference to chain calls95 * @see org.openqa.selenium.interactions.Actions#contextClick()96 */97 public MouseActions contextClick() {98 actions().contextClick().perform();99 return this;100 }101 /**102 * Moves the mouse from its current position (or 0,0) by the given offset. If the coordinates103 * provided are outside the viewport (the mouse will end up outside the browser window) then104 * the viewport is scrolled to match.105 * @param xOffset horizontal offset. A negative value means moving the mouse left.106 * @param yOffset vertical offset. A negative value means moving the mouse up.107 * @return this object reference to chain calls108 * @see org.openqa.selenium.interactions.Actions#moveByOffset(int, int)109 */110 public MouseActions moveByOffset(int xOffset, int yOffset) {111 actions().moveByOffset(xOffset, yOffset).perform();112 return this;113 }114}...

Full Screen

Full Screen

Source:Mouse_Hover.java Github

copy

Full Screen

1package mouse_Actions;23import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.interactions.HasInputDevices;8import org.openqa.selenium.interactions.Locatable;9import org.openqa.selenium.interactions.Mouse;10import org.openqa.selenium.interactions.internal.Coordinates;1112public class Mouse_Hover 13{1415 public static void main(String[] args) throws Exception 16 {17 WebDriver driver=new ChromeDriver();18 driver.get("https://www.hdfcbank.com/");19 driver.manage().window().maximize();20 21 22 //Enable MouseInterface class controls on browser23 Mouse mouse=((HasInputDevices)driver).getMouse();24 25 //Identify Target26 WebElement Products=driver.findElement(By.linkText("Products"));27 //Get element coordinate using locatable class28 Coordinates Products_Co=((Locatable)Products).getCoordinates();29 mouse.mouseMove(Products_Co);30 Thread.sleep(5000);31 32 //Identify Target33 WebElement Loan=driver.findElement(By.linkText("Loans"));34 //Get element coordinate using locatable class35 Coordinates Loan_Co=((Locatable)Loan).getCoordinates(); 36 mouse.mouseMove(Loan_Co);37 Thread.sleep(5000);38 39 WebElement Personal_Loan=driver.findElement(By.linkText("Personal Loan"));40 Coordinates Personal_Loan_co=((Locatable)Personal_Loan).getCoordinates();41 42 mouse.click(Personal_Loan_co);43 44 driver.close();4546 }4748} ...

Full Screen

Full Screen

Source:Coordinates.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.interactions.internal;18@Deprecated19/**20 * Provides coordinates of an element for advanced interactions. Note that some coordinates (such as21 * screen coordinates) are evaluated lazily since the element may have to be scrolled into view.22 * @deprecated Use {@link org.openqa.selenium.interactions.Coordinates}23 */24public interface Coordinates extends org.openqa.selenium.interactions.Coordinates {25}...

Full Screen

Full Screen

Source:TouchActions.java Github

copy

Full Screen

1package mouse_Actions;23import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.interactions.HasTouchScreen;8import org.openqa.selenium.interactions.Locatable;9import org.openqa.selenium.interactions.TouchScreen;10import org.openqa.selenium.interactions.internal.Coordinates;111213public class TouchActions {1415 public static void main(String[] args) 16 {17 //Keyboard interface class18 WebDriver driver=new ChromeDriver();19 driver.get("https://www.hdfcbank.com/");20 driver.manage().window().maximize();21 22 23 //Enable Touch controls on automation browser24 TouchScreen touch=((HasTouchScreen)driver).getTouch();25 26 //Duplicate element27 WebElement Element=driver.findElement(By.xpath("//input"));28 //Get Coordinate for element29 Coordinates Ele_co=((Locatable)Element).getCoordinates();30 31 32 touch.doubleTap(Ele_co);33 touch.singleTap(Ele_co);34 touch.longPress(Ele_co);35 36 37 /*38 * Tocuh action39 * https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/touch/TouchActions.html40 */41 42 43 44 }4546} ...

Full Screen

Full Screen

Source:Mouse.java Github

copy

Full Screen

1/*2Copyright 2007-2010 Selenium committers3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12 */13package org.openqa.selenium.interactions;14import org.openqa.selenium.interactions.internal.Coordinates;15/**16 * Interface representing basic mouse operations.17 */18public interface Mouse {19 void click(Coordinates where);20 void doubleClick(Coordinates where);21 void mouseDown(Coordinates where);22 void mouseUp(Coordinates where);23 void mouseMove(Coordinates where);24 /* Offset from the current location of the mouse pointer. */25 void mouseMove(Coordinates where, long xOffset, long yOffset);26 // Right-clicks an element.27 void contextClick(Coordinates where);28 // TODO: Scroll wheel support29}...

Full Screen

Full Screen

Source:TouchScreen_interface.java Github

copy

Full Screen

1package mouse_Actions;23import java.util.concurrent.TimeUnit;45import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.interactions.HasTouchScreen;10import org.openqa.selenium.interactions.Locatable;11import org.openqa.selenium.interactions.TouchScreen;12import org.openqa.selenium.interactions.internal.Coordinates;1314public class TouchScreen_interface {1516 public static void main(String[] args) 17 {1819 WebDriver driver=new ChromeDriver();20 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);21 driver.get("https://sampledomain.com/");22 driver.manage().window().maximize();23 24 25 //Enable touchactions on mobile interface26 27 TouchScreen touch=((HasTouchScreen)driver).getTouch();28 29 //Identity location of element30 WebElement Element=driver.findElement(By.id("xyz"));31 //get elemnet coordinates32 Coordinates obj_co=((Locatable)Element).getCoordinates();33 touch.singleTap(obj_co);34 35 3637 }3839} ...

Full Screen

Full Screen

Source:TouchScreen.java Github

copy

Full Screen

1package org.openqa.selenium.interactions;2import org.openqa.selenium.interactions.internal.Coordinates;3public abstract interface TouchScreen4{5 public abstract void singleTap(Coordinates paramCoordinates);6 7 public abstract void down(int paramInt1, int paramInt2);8 9 public abstract void up(int paramInt1, int paramInt2);10 11 public abstract void move(int paramInt1, int paramInt2);12 13 public abstract void scroll(Coordinates paramCoordinates, int paramInt1, int paramInt2);14 15 public abstract void doubleTap(Coordinates paramCoordinates);16 17 public abstract void longPress(Coordinates paramCoordinates);18 19 public abstract void scroll(int paramInt1, int paramInt2);20 21 public abstract void flick(int paramInt1, int paramInt2);22 23 public abstract void flick(Coordinates paramCoordinates, int paramInt1, int paramInt2, int paramInt3);24}...

Full Screen

Full Screen

Interface Coordinates

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.interactions.Actions;5import org.openqa.selenium.chrome.ChromeDriver;6public class MouseHoverDemo {7 public static void main(String[] args) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 driver.manage().window().maximize();11 System.out.println(driver.getTitle());12 Actions action = new Actions(driver);13 action.moveToElement(element).build().perform();14 Thread.sleep(3000);15 }16}

Full Screen

Full Screen

Interface Coordinates

Using AI Code Generation

copy

Full Screen

1public class CoordinatesExample {2public static void main(String[] args) {3 WebDriver driver = new FirefoxDriver();4 driver.manage().window().maximize();5 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);6 Locatable locatable = (Locatable) e;7 Coordinates coordinates = locatable.getCoordinates();8 System.out.println(coordinates.onScreen());9 System.out.println(coordinates.inViewPort());10 System.out.println(coordinates.inViewPort());11 System.out.println(coordinates.inDom());12 System.out.println(coordinates.inDom());13 System.out.println(coordinates.onScreen());14 System.out.println(coordinates.inViewPort());15 System.out.println(coordinates.inDom());16 System.out.println(coordinates.inDom());17 System.out.println(coordinates.onScreen());18 System.out.println(coordinates.inViewPort());19 System.out.println(coordinates.inDom());20 System.out.println(coordinates.inDom());21 System.out.println(coordinates.onScreen());22 System.out.println(coordinates.in

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Interface-Coordinates

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful