How to use addAction method of org.openqa.selenium.interactions.Sequence class

Best Selenium code snippet using org.openqa.selenium.interactions.Sequence.addAction

Source:MyActions.java Github

copy

Full Screen

...41 public MyActions keyDown(Keys theKey) {42 return keyDown(null, theKey);43 }44 public MyActions keyDown(WebElement element, Keys theKey) {45 action.addAction(new KeyDownAction(keyboard, mouse, (Locatable)element, theKey));46 return this;47 }48 public MyActions keyUp(Keys theKey) {49 return keyUp(null, theKey);50 }51 public MyActions keyUp(WebElement element, Keys theKey) {52 action.addAction(new KeyUpAction(keyboard, mouse, (Locatable)element, theKey));53 return this;54 }55 public MyActions sendKeys(CharSequence keysToSend[]) {56 return sendKeys(null, keysToSend);57 }58 public MyActions sendKeys(WebElement element, CharSequence keysToSend[]) {59 action.addAction(new SendKeysAction(keyboard, mouse, (Locatable)element, keysToSend));60 return this;61 }62 public MyActions clickAndHold(WebElement onElement) {63 action.addAction(new ClickAndHoldAction(mouse, (Locatable)onElement));64 return this;65 }66 public MyActions clickAndHold() {67 return clickAndHold(null);68 }69 public MyActions release(WebElement onElement) {70 action.addAction(new ButtonReleaseAction(mouse, (Locatable)onElement));71 return this;72 }73 public MyActions release() {74 return release(null);75 }76 public MyActions click(WebElement onElement) {77 action.addAction(new ClickAction(mouse, (Locatable)onElement));78 return this;79 }80 public MyActions click() {81 return click(null);82 }83 public MyActions doubleClick(WebElement onElement) {84 action.addAction(new DoubleClickAction(mouse, (Locatable)onElement));85 return this;86 }87 public MyActions doubleClick() {88 return doubleClick(null);89 }90 public MyActions moveToElement(WebElement toElement) {91 action.addAction(new MoveMouseAction(mouse, (Locatable)toElement));92 return this;93 }94 public MyActions moveToElement(WebElement toElement, int xOffset, int yOffset) {95 action.addAction(new MoveToOffsetAction(mouse, (Locatable)toElement, xOffset, yOffset));96 return this;97 }98 public MyActions moveByOffset(int xOffset, int yOffset) {99 action.addAction(new MoveToOffsetAction(mouse, null, xOffset, yOffset));100 return this;101 }102 public MyActions contextClick(WebElement onElement) {103 action.addAction(new ContextClickAction(mouse, (Locatable)onElement));104 return this;105 }106 public MyActions contextClick() {107 return contextClick(null);108 }109 public MyActions dragAndDrop(WebElement source, WebElement target) {110 action.addAction(new ClickAndHoldAction(mouse, (Locatable)source));111 action.addAction(new MoveMouseAction(mouse, (Locatable)target));112 action.addAction(new ButtonReleaseAction(mouse, (Locatable)target));113 return this;114 }115 public MyActions dragAndDropBy(WebElement source, int xOffset, int yOffset) {116 action.addAction(new ClickAndHoldAction(mouse, (Locatable)source));117 action.addAction(new MoveToOffsetAction(mouse, null, xOffset, yOffset));118 action.addAction(new ButtonReleaseAction(mouse, null));119 return this;120 }121 public Action build() {122 MyCompositeAction toReturn = action;123 resetCompositeAction();124 return toReturn;125 }126 public void perform() {127 build().perform();128 }129}...

Full Screen

Full Screen

Source:Edition107_Base.java Github

copy

Full Screen

...49 AppiumDriver<MobileElement> d = getDriver();50 boolean isAndroid = d instanceof AndroidDriver<?>;51 PointerInput input = new PointerInput(Kind.TOUCH, "finger1");52 Sequence swipe = new Sequence(input, 0);53 swipe.addAction(input.createPointerMove(Duration.ZERO, Origin.viewport(), start.x, start.y));54 swipe.addAction(input.createPointerDown(MouseButton.LEFT.asArg()));55 if (isAndroid) {56 duration = duration.dividedBy(ANDROID_SCROLL_DIVISOR);57 } else {58 swipe.addAction(new Pause(input, duration));59 duration = Duration.ZERO;60 }61 swipe.addAction(input.createPointerMove(duration, Origin.viewport(), end.x, end.y));62 swipe.addAction(input.createPointerUp(MouseButton.LEFT.asArg()));63 d.perform(ImmutableList.of(swipe));64 }65 protected void swipe(double startXPct, double startYPct, double endXPct, double endYPct, Duration duration) {66 Dimension size = getWindowSize();67 Point start = new Point((int)(size.width * startXPct), (int)(size.height * startYPct));68 Point end = new Point((int)(size.width * endXPct), (int)(size.height * endYPct));69 swipe(start, end, duration);70 }71 protected void scroll(ScrollDirection dir, double distance) {72 if (distance < 0 || distance > 1) {73 throw new Error("Scroll distance must be between 0 and 1");74 }75 Dimension size = getWindowSize();76 Point midPoint = new Point((int)(size.width * 0.5), (int)(size.height * 0.5));...

Full Screen

Full Screen

Source:Edition116_iOS_Springboard.java Github

copy

Full Screen

...54 }55 protected void swipe(Point start, Point end, Duration duration) {56 PointerInput input = new PointerInput(Kind.TOUCH, "finger1");57 Sequence swipe = new Sequence(input, 0);58 swipe.addAction(input.createPointerMove(Duration.ZERO, Origin.viewport(), start.x, start.y));59 swipe.addAction(input.createPointerDown(MouseButton.LEFT.asArg()));60 swipe.addAction(new Pause(input, duration));61 duration = Duration.ZERO;62 swipe.addAction(input.createPointerMove(duration, Origin.viewport(), end.x, end.y));63 swipe.addAction(input.createPointerUp(MouseButton.LEFT.asArg()));64 driver.perform(ImmutableList.of(swipe));65 }66 protected void swipe(double startXPct, double startYPct, double endXPct, double endYPct, Duration duration) {67 Dimension size = driver.manage().window().getSize();68 Point start = new Point((int)(size.width * startXPct), (int)(size.height * startYPct));69 Point end = new Point((int)(size.width * endXPct), (int)(size.height * endYPct));70 swipe(start, end, duration);71 }72 protected void pressHome() {73 driver.executeScript("mobile: pressButton", ImmutableMap.of("name", "home"));74 }75 protected void swipeToPrevScreen() {76 swipe(0.1, 0.5, 0.9, 0.5, Duration.ofMillis(750));77 }...

Full Screen

Full Screen

Source:Edition029_W3C_Actions.java Github

copy

Full Screen

...57 private void drawCircle (AppiumDriver driver, Point origin, double radius, int steps) {58 Point firstPoint = getPointOnCircle(0, steps, origin, radius);59 PointerInput finger = new PointerInput(Kind.TOUCH, "finger");60 Sequence circle = new Sequence(finger, 0);61 circle.addAction(finger.createPointerMove(NO_TIME, VIEW, firstPoint.x, firstPoint.y));62 circle.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));63 for (int i = 1; i < steps + 1; i++) {64 Point point = getPointOnCircle(i, steps, origin, radius);65 circle.addAction(finger.createPointerMove(STEP_DURATION, VIEW, point.x, point.y));66 }67 circle.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));68 driver.perform(Arrays.asList(circle));69 }70}...

Full Screen

Full Screen

Source:Ch_05_03_Touch_Actions_After.java Github

copy

Full Screen

...48 Interaction pressDown = finger.createPointerDown(MouseButton.LEFT.asArg());49 Interaction moveToEnd = finger.createPointerMove(Duration.ofMillis(1000), Origin.viewport(), 520, 490);50 Interaction pressUp = finger.createPointerUp(MouseButton.LEFT.asArg());51 Sequence swipe = new Sequence(finger, 0);52 swipe.addAction(moveToStart);53 swipe.addAction(pressDown);54 swipe.addAction(moveToEnd);55 swipe.addAction(pressUp);56 driver.perform(Arrays.asList(swipe));57 driver.findElement(MobileBy.AccessibilityId("Stratus"));58 }59}...

Full Screen

Full Screen

Source:TestListView.java Github

copy

Full Screen

...50 Interaction pressup = doigt.createPointerUp(MouseButton.LEFT.asArg());51 52 //sequence des moviments53 Sequence swip = new Sequence(doigt, 0);54 swip.addAction(movetostart);55 swip.addAction(pressdown);56 swip.addAction(movetoend);57 swip.addAction(pressup);58 59 driver.perform(Arrays.asList(swip));60 61 WebElement cloudelement = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Stratus")));62 cloudelement.click();63 Thread.sleep(3000);64 }65 66 67} ...

Full Screen

Full Screen

Source:Edition119_Base.java Github

copy

Full Screen

...26 protected void tapAtPoint(Point point) {27 AppiumDriver<MobileElement> d = getDriver();28 PointerInput input = new PointerInput(Kind.TOUCH, "finger1");29 Sequence tap = new Sequence(input, 0);30 tap.addAction(input.createPointerMove(Duration.ZERO, Origin.viewport(), point.x, point.y));31 tap.addAction(input.createPointerDown(MouseButton.LEFT.asArg()));32 tap.addAction(new Pause(input, Duration.ofMillis(200)));33 tap.addAction(input.createPointerUp(MouseButton.LEFT.asArg()));34 d.perform(ImmutableList.of(tap));35 }36 protected void tapElement(WebElement el) {37 tapElementAt(el, 0.5, 0.5);38 }39 protected void tapElementAt(WebElement el, double xPct, double yPct) {40 Rectangle elRect = el.getRect();41 Point point = new Point(42 elRect.x + (int)(elRect.getWidth() * xPct),43 elRect.y + (int)(elRect.getHeight() * yPct)44 );45 tapAtPoint(point);46 }47}...

Full Screen

Full Screen

Source:DrawCircle.java Github

copy

Full Screen

...11 public void drawCircle (AppiumDriver driver, Point origin, double radius, int steps) {12 Point firstPoint = getPointOnCircle(0, steps, origin, radius);13 PointerInput finger = new PointerInput(Kind.TOUCH, "finger");14 Sequence circle = new Sequence(finger, 0);15 circle.addAction(finger.createPointerMove(Duration.ofSeconds(1), PointerInput.Origin.viewport(), firstPoint.x, firstPoint.y));16 circle.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));17 for (int i = 1; i < steps + 1; i++) {18 Point point = getPointOnCircle(i, steps, origin, radius);19 circle.addAction(finger.createPointerMove(Duration.ofSeconds(1), PointerInput.Origin.viewport(), point.x, point.y));20 }21 circle.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));22 driver.perform(Arrays.asList(circle));23 }24 25 }26 27}...

Full Screen

Full Screen

addAction

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.interactions.Actions;4import org.openqa.selenium.interactions.Sequence;5import org.openqa.selenium.interactions.SourceType;6import org.openqa.selenium.interactions.PointerInput;7import org.openqa.selenium.interactions.PointerInput.Kind;8import org.openqa.selenium.interactions.PointerInput.MouseButton;9import org.openqa.selenium.interactions.PointerInput.Origin;10import org.openqa.selenium.interactions.Action;11import org.openqa.selenium.interactions.Actions;12import org.openqa.selenium.interactions.Sequence;13import org.openqa.selenium.interactions.SourceType;14import org.openqa.selenium.interactions.PointerInput;15import org.openqa.selenium.interactions.PointerInput.Kind;16import org.openqa.selenium.interactions.PointerInput.MouseButton;17import org.openqa.selenium.interactions.PointerInput.Origin;18import org.openqa.selenium.interactions.Action;19import org.openqa.selenium.interactions.Actions;20import org.openqa.selenium.interactions.Sequence;21import org.openqa.selenium.interactions.SourceType;22import org.openqa.selenium.interactions.PointerInput;23import org.openqa.selenium.interactions.PointerInput.Kind;24import org.openqa.selenium.interactions.PointerInput.MouseButton;25import org.openqa.selenium.interactions.PointerInput.Origin;26import org.openqa.selenium.interactions.Action;27import org.openqa.selenium.interactions.Actions;28import org.openqa.selenium.interactions.Sequence;29import org.openqa.selenium.interactions.SourceType;30import org.openqa.selenium.interactions.PointerInput;31import org.openqa.selenium.interactions.PointerInput.Kind;32import org.openqa.selenium.interactions.PointerInput.MouseButton;33import org.openqa.selenium.interactions.PointerInput.Origin;34import org.openqa.selenium.interactions.Action;35import org.openqa.selenium.interactions.Actions;36import org.openqa.selenium.interactions.Sequence;37import org.openqa.selenium.interactions.SourceType;38import org.openqa.selenium.interactions.PointerInput;39import org.openqa.selenium.interactions.PointerInput.Kind;40import org.openqa.selenium.interactions.PointerInput.MouseButton;41import org.openqa.selenium.interactions.PointerInput.Origin;42import org.openqa.selenium.interactions.Action;43import org.openqa.selenium.interactions.Actions;44import org.openqa.selenium.interactions.Sequence;45import org.openqa.selenium.interactions.SourceType;46import org.openqa.selenium.interactions.PointerInput;47import org.openqa.selenium.interactions.PointerInput.Kind;48import org.openqa.selenium.interactions.PointerInput.MouseButton;49import org.openqa.selenium.interactions.PointerInput.Origin;50import org.openqa.selenium.interactions.Action;51import org.openqa.selenium.interactions.Actions;52import org.openqa.selenium.interactions.Sequence;53import org.openqa.selenium.interactions.SourceType;54import org.openqa.selenium.interactions.PointerInput;55import

Full Screen

Full Screen

addAction

Using AI Code Generation

copy

Full Screen

1Actions builder = new Actions(driver);2builder.doubleClick(element);3builder.perform();4Actions builder = new Actions(driver);5builder.doubleClick(element);6builder.perform();7Actions builder = new Actions(driver);8builder.doubleClick(element);9builder.perform();10Actions builder = new Actions(driver);11builder.doubleClick(element);12builder.perform();13Actions builder = new Actions(driver);14builder.doubleClick(element);15builder.perform();16Actions builder = new Actions(driver);17builder.doubleClick(element);18builder.perform();19Actions builder = new Actions(driver);20builder.doubleClick(element);21builder.perform();22Actions builder = new Actions(driver);23builder.doubleClick(element);24builder.perform();25Actions builder = new Actions(driver);26builder.doubleClick(element);27builder.perform();28Actions builder = new Actions(driver);29builder.doubleClick(element);30builder.perform();31Actions builder = new Actions(driver);32builder.doubleClick(element);

Full Screen

Full Screen

addAction

Using AI Code Generation

copy

Full Screen

1package com.zetcode;2import org.openqa.selenium.By;3import org.openqa.selenium.Keys;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.interactions.Actions;8import org.openqa.selenium.interactions.Sequence;9import java.util.concurrent.TimeUnit;10public class SequenceEx {11 public static void main(String[] args) {12 System.setProperty("webdriver.chrome.driver", "/home/janbodnar/Downloads/chromedriver_linux64/chromedriver");13 WebDriver driver = new ChromeDriver();14 driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);15 WebElement searchBox = driver.findElement(By.name("q"));16 searchBox.sendKeys("Selenium");17 Actions builder = new Actions(driver);18 Sequence sequence = new Sequence(builder);19 sequence.addAction(builder.keyDown(Keys.SHIFT).sendKeys("selenium").keyUp(Keys.SHIFT).build());20 sequence.addAction(builder.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build());21 sequence.addAction(builder.sendKeys(Keys.ENTER).build());22 builder.perform(sequence);23 driver.quit();24 }25}

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 method in Sequence

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful