How to use perform method of org.openqa.selenium.interactions.Actions class

Best Selenium code snippet using org.openqa.selenium.interactions.Actions.perform

Source:PageElementActions.java Github

copy

Full Screen

...12 * bind via {@link com.atlassian.pageobjects.PageBinder} to get instance explicitly.13 *14 * <p/>15 * Build a sequence of actions to execute by using the builder-style methods of this class. After that16 * {@link #build()} a resulting action to execute, or just {@link #perform()} the actions straight away.17 *18 * @see Actions19 * @since 2.120 */21public class PageElementActions22{23 @Inject24 private AtlassianWebDriver webDriver;25 private Actions actions;26 private Actions getActions()27 {28 if (actions == null)29 {30 actions = new Actions(webDriver.getDriver());31 }32 return actions;33 }34 /**35 * @see Actions#keyDown(org.openqa.selenium.Keys)36 */37 public PageElementActions keyDown(Keys theKey)38 {39 getActions().keyDown(theKey);40 return this;41 }42 /**43 * @see Actions#keyDown(org.openqa.selenium.WebElement, org.openqa.selenium.Keys)44 */45 public PageElementActions keyDown(PageElement element, Keys theKey)46 {47 getActions().keyDown(getWebElement(element), theKey);48 return this;49 }50 /**51 * @see Actions#keyUp(org.openqa.selenium.Keys)52 */53 public PageElementActions keyUp(Keys theKey)54 {55 getActions().keyUp(theKey);56 return this;57 }58 /**59 * @see Actions#keyUp(org.openqa.selenium.WebElement, org.openqa.selenium.Keys)60 */61 public PageElementActions keyUp(PageElement element, Keys theKey)62 {63 getActions().keyUp(getWebElement(element), theKey);64 return this;65 }66 /**67 * @see Actions#sendKeys(CharSequence...)68 */69 public PageElementActions sendKeys(CharSequence... keysToSend)70 {71 getActions().sendKeys(keysToSend);72 return this;73 }74 /**75 * @see Actions#sendKeys(org.openqa.selenium.WebElement, CharSequence...)76 */77 public PageElementActions sendKeys(PageElement element, CharSequence... keysToSend)78 {79 getActions().sendKeys(getWebElement(element), keysToSend);80 return this;81 }82 /**83 * @see org.openqa.selenium.interactions.Actions#clickAndHold(org.openqa.selenium.WebElement)84 */85 public PageElementActions clickAndHold(PageElement onElement)86 {87 getActions().clickAndHold(getWebElement(onElement));88 return this;89 }90 /**91 * @see org.openqa.selenium.interactions.Actions#clickAndHold()92 */93 public PageElementActions clickAndHold()94 {95 getActions().clickAndHold();96 return this;97 }98 /**99 * @see org.openqa.selenium.interactions.Actions#release(org.openqa.selenium.WebElement)100 */101 public PageElementActions release(PageElement onElement)102 {103 getActions().release(getWebElement(onElement));104 return this;105 }106 /**107 * @see org.openqa.selenium.interactions.Actions#release()108 */109 public PageElementActions release()110 {111 getActions().release();112 return this;113 }114 /**115 * @see Actions#click(org.openqa.selenium.WebElement)116 */117 public PageElementActions click(PageElement onElement)118 {119 getActions().click(getWebElement(onElement));120 return this;121 }122 /**123 * @see org.openqa.selenium.interactions.Actions#click()124 */125 public PageElementActions click() {126 getActions().click();127 return this;128 }129 /**130 * @see org.openqa.selenium.interactions.Actions#doubleClick(org.openqa.selenium.WebElement)131 */132 public PageElementActions doubleClick(PageElement onElement)133 {134 getActions().doubleClick(getWebElement(onElement));135 return this;136 }137 /**138 * @see org.openqa.selenium.interactions.Actions#doubleClick()139 */140 public PageElementActions doubleClick()141 {142 getActions().doubleClick();143 return this;144 }145 /**146 * @see Actions#moveToElement(org.openqa.selenium.WebElement)147 */148 public PageElementActions moveToElement(PageElement toElement)149 {150 getActions().moveToElement(getWebElement(toElement));151 return this;152 }153 /**154 * @see Actions#moveToElement(org.openqa.selenium.WebElement, int, int)155 */156 public PageElementActions moveToElement(PageElement toElement, int xOffset, int yOffset)157 {158 getActions().moveToElement(getWebElement(toElement), xOffset, yOffset);159 return this;160 }161 /**162 * @see Actions#moveByOffset(int, int)163 */164 public PageElementActions moveByOffset(int xOffset, int yOffset)165 {166 getActions().moveByOffset(xOffset, yOffset);167 return this;168 }169 /**170 * @see Actions#contextClick(org.openqa.selenium.WebElement)171 */172 public PageElementActions contextClick(PageElement onElement)173 {174 getActions().contextClick(getWebElement(onElement));175 return this;176 }177 /**178 * @see Actions#dragAndDrop(org.openqa.selenium.WebElement, org.openqa.selenium.WebElement)179 */180 public PageElementActions dragAndDrop(PageElement source, PageElement target)181 {182 getActions().dragAndDrop(getWebElement(source), getWebElement(target));183 return this;184 }185 /**186 * @see Actions#dragAndDropBy(org.openqa.selenium.WebElement, int, int)187 */188 public PageElementActions dragAndDropBy(PageElement source, int xOffset, int yOffset) {189 getActions().dragAndDropBy(getWebElement(source), xOffset, yOffset);190 return this;191 }192 /**193 * Build an action to execute out of the provided sequence. This builder will be reset after calling that method.194 *195 * @return196 */197 Action build()198 {199 return getActions().build();200 }201 /**202 * Execute the specified series of actions. This also resets the actions.203 */204 public void perform()205 {206 getActions().perform();207 }208 /**209 * Reset the sequence of actions to execute.210 *211 * @return this actions instance212 */213 public PageElementActions reset()214 {215 getActions().build(); // resets216 return this;217 }218}...

Full Screen

Full Screen

Source:CompositeActions.java Github

copy

Full Screen

...40@Aspect41public class CompositeActions {42 43 /**44 * Slows down any action performed through CompositeActions by 200 ms45 * It requires to use {@link EventFiringWebDriver} because we intercept the "perform()" method of any {@link org.openqa.selenium.interactions.Action}46 * Eclipse project also need to have its Aspect build path configured with selenium-api artifact47 * @param joinPoint48 */49 @After("call(public * org.openqa.selenium.interactions.Action+.perform (..))")50 public void slowDown(JoinPoint joinPoint) {51 WaitHelper.waitForMilliSeconds(200);52 }53 54 /**55 * Update window handles when a click is requested in a composite Action (to get the same behavior between native clicks56 * and clicks in CompositeAction57 * Capture is done on all Action sub-classes, else it would never be done58 * 59 * TO KEEP until ClickAction and other equivalents are there in selenium code60 * 61 * @param joinPoint62 * @throws SecurityException 63 * @throws NoSuchFieldException 64 * @throws IllegalAccessException 65 * @throws IllegalArgumentException 66 */67 @Before("call(public void org.openqa.selenium.interactions.Action+.perform ())")68 public void updateHandles(JoinPoint joinPoint) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {69 if (!(joinPoint.getTarget() instanceof CompositeAction)) {70 return;71 }72 CompositeAction compositeAction = (CompositeAction)joinPoint.getTarget();73 Field actionListField = CompositeAction.class.getDeclaredField("actionsList");74 actionListField.setAccessible(true);75 @SuppressWarnings("unchecked")76 List<Action> actionsList = (List<Action>)actionListField.get(compositeAction);77 78 boolean clickRequested = false;79 for (Action action: actionsList) {80 if (action instanceof ClickAction) {81 clickRequested = true;82 }83 }84 85 if (clickRequested) {86 ((CustomEventFiringWebDriver)WebUIDriver.getWebDriver(false)).updateWindowsHandles();87 }88 }89 90 /**91 * Intercept calls to {@link org.openqa.selenium.remote.RemoteWebDriver.perform(Collection<Sequence> actions)} method which handles92 * the new way of sending composite actions93 * @param joinPoint94 * @throws NoSuchFieldException95 * @throws SecurityException96 * @throws IllegalArgumentException97 * @throws IllegalAccessException98 */99 @Before("execution(public void org.openqa.selenium.remote.RemoteWebDriver.perform (..))")100 public void updateHandlesNewActions(JoinPoint joinPoint) throws NoSuchFieldException, IllegalAccessException {101102 @SuppressWarnings("unchecked")103 Collection<Sequence> sequences = (Collection<Sequence>)joinPoint.getArgs()[0];104105 for (Sequence sequence: sequences) {106 Field actionsField = Sequence.class.getDeclaredField("actions");107 actionsField.setAccessible(true);108 @SuppressWarnings("unchecked")109 LinkedList<Interaction> actionsList = (LinkedList<Interaction>)actionsField.get(sequence);110 111 updateWindowHandles(actionsList);112 }113 } ...

Full Screen

Full Screen

Source:MyActions.java Github

copy

Full Screen

...122 MyCompositeAction toReturn = action;123 resetCompositeAction();124 return toReturn;125 }126 public void perform() {127 build().perform();128 }129}...

Full Screen

Full Screen

Source:MouseActions.java Github

copy

Full Screen

...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:KeyboardActions.java Github

copy

Full Screen

...48 * @return this object reference to chain calls49 * @see org.openqa.selenium.interactions.Actions#keyDown(CharSequence)50 */51 public KeyboardActions keyDown(Keys theKey) {52 actions().keyDown(theKey).perform();53 return this;54 }55 /**56 * Performs a modifier key release. Releasing a non-depressed modifier key will yield undefined57 * behaviour.58 *59 * @param theKey Either {@link Keys#SHIFT}, {@link Keys#ALT} or {@link Keys#CONTROL}.60 * @return this object reference to chain calls61 * @see org.openqa.selenium.interactions.Actions#keyUp(CharSequence)62 */63 public KeyboardActions keyUp(Keys theKey) {64 actions().keyUp(theKey).perform();65 return this;66 }67 /**68 * Sends keys to the active element. This differs from calling69 * {@link WebElement#sendKeys(CharSequence...)} on the active element in two ways:70 * <ul>71 * <li>The modifier keys included in this call are not released.</li>72 * <li>There is no attempt to re-focus the element - so sendKeys(Keys.TAB) for switching73 * elements should work. </li>74 * </ul>75 *76 * @param keysToSend The keys.77 * @return A self reference.78 * @see org.openqa.selenium.interactions.Actions#sendKeys(CharSequence...)79 */80 public KeyboardActions sendKeys(CharSequence... keysToSend) {81 actions().sendKeys(keysToSend).perform();82 return this;83 }84}...

Full Screen

Full Screen

Source:Android_Swipe.java Github

copy

Full Screen

...37 //your relationship38 WebElement YourRelationshipSwipe1 = driver.findElement(By.xpath("//div[@id='rel-scroll']/ul/li[2]/div/a/img"));39 //System.out.println(swipe2.getTagName()); 40 Action_flick.flick(YourRelationshipSwipe1, -100, 0, FlickAction.SPEED_NORMAL);41 Action_flick.build().perform();42 Thread.sleep(1000);43 44 //content explorer45 WebElement ContentExplorerSwipe1 = driver.findElement(By.xpath("//*[@id='exp-scroll']/div/article[4]/a"));46 Action_flick.flick(ContentExplorerSwipe1, -50, 0, FlickAction.SPEED_NORMAL);47 Thread.sleep(100);48 Action_flick.build().perform();49 Thread.sleep(1000);50 //premium content51 WebElement PremiumSwipe1 = driver.findElement(By.xpath("//*[@id='prem-scroll']/div/article[4]/a/span"));52 Action_flick.flick(PremiumSwipe1, -50, 0, FlickAction.SPEED_NORMAL);53 Thread.sleep(100);54 Action_flick.build().perform();55 Thread.sleep(1000);56 //more from orange57 WebElement MoreSwipe1 = driver.findElement(By.xpath("//*[@id='more-scroll']/div/article[4]/a"));58 Action_flick.flick(MoreSwipe1, -50, 0, FlickAction.SPEED_NORMAL);59 Thread.sleep(100);60 Action_flick.build().perform();61 Thread.sleep(1000);62 //trending search63 WebElement TrendingSwipe1 = driver.findElement(By.xpath("//*[@id='bookmarks-scroll']/ul/li[4]"));64 Action_flick.flick(TrendingSwipe1, -50, 0, FlickAction.SPEED_NORMAL);65 Thread.sleep(100);66 Action_flick.build().perform();67 68 }69}...

Full Screen

Full Screen

Source:Actions.java Github

copy

Full Screen

...35 element = (WebElement) Browser.getWaits().wait(driver, ElementTag, LocateBy,ExpectedCondition.visibilityOfElementLocated, 2, null);36 //JavascriptExecutor js = (JavascriptExecutor)driver;37 //WebElement searchElement = driver.findElement(By.linkText(eventName));38 org.openqa.selenium.interactions.Actions actions = new org.openqa.selenium.interactions.Actions(driver);39 actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).build().perform();40 actions.keyUp(Keys.CONTROL).build().perform();41 //Object response = js.executeScript("arguments[0].scrollIntoView(true);", element);42 //Thread.sleep(5000); 43 timer++;44 }else45 {46 return true;47 }48 }49 }catch(Exception e)50 {51 e.printStackTrace();52 }53 54 return result;55 }56 public boolean scrollPageIntoView(WebDriver driver, String ElementTag, int timeOut)57 {58 59 boolean result = false;60 int timer = 1;61 WebElement element = null;62 try{63 64 while(timer<timeOut)65 {66 if(element==null)67 {68 element = (WebElement) Browser.getWaits().wait(driver, ElementTag,ExpectedCondition.visibilityOfElementLocated, 2, null);69 org.openqa.selenium.interactions.Actions actions = new org.openqa.selenium.interactions.Actions(driver);70 actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).build().perform();71 actions.keyUp(Keys.CONTROL).build().perform(); 72 timer++;73 }else74 {75 return true;76 }77 }78 }catch(Exception e)79 {80 e.printStackTrace();81 }82 83 return result;84 }85 public void clear(WebElement element) {...

Full Screen

Full Screen

Source:DragTo.java Github

copy

Full Screen

...22 mouse = ((HasInputDevices) browser.getWebDriver()).getMouse();23 keyboard = ((HasInputDevices) browser.getWebDriver()).getKeyboard();24 }25 26 protected void perform() throws Exception {27 if(element != null) {28 if(targetElement != null) {29 browser.log().info("Dragging {} to {}", element, targetElement);30 // TODO Only working if native events are enabled on this platform31 new ClickAndHoldAction(mouse, (Locatable) element.getSeleniumElement()).perform();32 new MoveMouseAction(mouse, (Locatable) targetElement.getSeleniumElement()).perform();33 new ButtonReleaseAction(mouse, null).perform();34// Action dragAction = new Actions(browser.getWebDriver()).dragAndDrop(element.getSeleniumElement(), targetElement.getSeleniumElement()).build();35// dragAction.perform();36// element.getSeleniumElement().dragAndDropOn(targetElement.getSeleniumElement());37 } else {38 browser.log().warn("Target element to drag on does not exist");39 }40 } else {41 browser.log().warn("Element to drag does not exist");42 }43 }44}...

Full Screen

Full Screen

perform

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.interactions.Actions;4import org.openqa.selenium.Keys;5public class ActionsClassEx {6 public static void main(String[] args) {7 WebDriver driver = new ChromeDriver();8 Actions actions = new Actions(driver);9 actions.sendKeys(Keys.ENTER).perform();10 driver.quit();11 }12}

Full Screen

Full Screen

perform

Using AI Code Generation

copy

Full Screen

1Actions actions = new Actions(driver);2actions.dragAndDrop(dragElement, dropElement).perform();3Actions actions = new Actions(driver);4actions.clickAndHold(dragElement).moveToElement(dropElement).release(dropElement).perform();5Actions actions = new Actions(driver);6actions.clickAndHold(dragElement).moveToElement(dropElement).release().perform();7Actions actions = new Actions(driver);8actions.dragAndDropBy(dragElement, xOffset, yOffset).perform();9Actions actions = new Actions(driver);10actions.clickAndHold(dragElement).moveByOffset(xOffset, yOffset).release().perform();11Actions actions = new Actions(driver);12actions.clickAndHold(dragElement).moveByOffset(xOffset, yOffset).release(dropElement).perform();13Actions actions = new Actions(driver);14actions.clickAndHold(dragElement).moveToElement(dropElement, xOffset, yOffset).release(dropElement).perform();15Actions actions = new Actions(driver);16actions.clickAndHold(dragElement).moveToElement(dropElement, xOffset, yOffset).release().perform();17Actions actions = new Actions(driver);18actions.dragAndDropBy(dragElement, xOffset, yOffset).perform();19Actions actions = new Actions(driver);20actions.clickAndHold(dragElement).moveByOffset(xOffset, yOffset).release().perform();21Actions actions = new Actions(driver);22actions.clickAndHold(dragElement).moveToElement

Full Screen

Full Screen

perform

Using AI Code Generation

copy

Full Screen

1Actions act = new Actions(driver);2act.sendKeys(Keys.CONTROL).sendKeys(Keys.TAB).sendKeys(Keys.CONTROL).perform();3Actions act = new Actions(driver);4act.sendKeys(Keys.CONTROL).sendKeys(Keys.TAB).sendKeys(Keys.CONTROL).perform();5Actions act = new Actions(driver);6act.sendKeys(Keys.CONTROL).sendKeys(Keys.TAB).sendKeys(Keys.CONTROL).perform();7Actions act = new Actions(driver);8act.sendKeys(Keys.CONTROL).sendKeys(Keys.TAB).sendKeys(Keys.CONTROL).perform();9Actions act = new Actions(driver);10act.sendKeys(Keys.CONTROL).sendKeys(Keys.TAB).sendKeys(Keys.CONTROL).perform();11Actions act = new Actions(driver);12act.sendKeys(Keys.CONTROL).sendKeys(Keys.TAB).sendKeys(Keys.CONTROL).perform();13Actions act = new Actions(driver);

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful