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

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

Source:WebDriverUtils.java Github

copy

Full Screen

...178 }179 public Actions click(BaseElement target) {180 return getActions().click(target);181 }182 public Actions clickAndHold() {183 return getActions().clickAndHold();184 }185 public Actions clickAndHold(BaseElement target) {186 return getActions().clickAndHold(target);187 }188 public Actions rightClick() {189 return getActions().contextClick();190 }191 public Actions rightClick(BaseElement target) {192 return getActions().contextClick(target);193 }194 public Actions doubleClick() {195 return getActions().doubleClick();196 }197 public Actions doubleClick(BaseElement target) {198 return getActions().doubleClick(target);199 }200 public Actions dragAndDrop(BaseElement source, BaseElement target) {...

Full Screen

Full Screen

Source:TestLayoutClickListenersTest.java Github

copy

Full Screen

...63 public void dragInGridLayout() {64 GridLayoutElement layout = $(GridLayoutElement.class).first();65 // Drag inside the first label in this layout66 LabelElement label = layout.$(LabelElement.class).first();67 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(label, getXOffset(label, 40), getYOffset(label, 8)).clickAndHold().moveByOffset((-20), 0).release().perform();68 assertLogText("Mouse dragged in GridLayout", "1. GridLayout: left click on This is label 1");69 // Drag from the third label to a text field in this layout70 label = layout.$(LabelElement.class).get(2);71 TextFieldElement textField = layout.$(TextFieldElement.class).get(3);72 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(label, getXOffset(label, 40), getYOffset(label, 8)).clickAndHold().moveToElement(textField, getXOffset(textField, 46), getYOffset(textField, 33)).release().perform();73 assertLogText("Expected the drag to be ignored between elements", "1. GridLayout: left click on This is label 1");74 }75 @Test76 public void dragInVerticalLayout() {77 VerticalLayoutElement layout = $(VerticalLayoutElement.class).get(4);78 // Drag inside the first text field79 TextFieldElement textField = layout.$(TextFieldElement.class).first();80 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(textField, getXOffset(textField, 25), getYOffset(textField, 9)).clickAndHold().moveByOffset((-20), 0).release().perform();81 assertLogText("Mouse dragged in VerticalLayout", "1. VerticalLayout: left click on This is tf5");82 // Drag from a caption to its text field83 textField = layout.$(TextFieldElement.class).get(4);84 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(textField, getXOffset(textField, 28), getYOffset(textField, 11)).clickAndHold().moveToElement(textField, getXOffset(textField, 39), getYOffset(textField, 30)).release().perform();85 assertLogText("Expected the drag to be ignored between elements", "1. VerticalLayout: left click on This is tf5");86 }87 @Test88 public void dragInAbsoluteLayout() {89 AbsoluteLayoutElement layout = $(AbsoluteLayoutElement.class).first();90 // Drag inside the first text field's caption91 TextFieldElement firstTextField = layout.$(TextFieldElement.class).first();92 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(firstTextField, getXOffset(firstTextField, 21), getYOffset(firstTextField, 9)).clickAndHold().moveByOffset((-10), 0).release().perform();93 assertLogText("Mouse dragged in AbsoluteLayout", "1. AbsoluteLayout: left click on This is its caption");94 // Drag from a text field to another text field95 TextFieldElement otherTextField = layout.$(TextFieldElement.class).get(1);96 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(otherTextField, getXOffset(otherTextField, 54), getYOffset(otherTextField, 7)).clickAndHold().moveToElement(firstTextField, getXOffset(firstTextField, 52), getYOffset(firstTextField, 10)).release().perform();97 assertLogText("Expected the drag to be ignored between elements", "1. AbsoluteLayout: left click on This is its caption");98 }99 @Test100 public void dragInCSSLayout() {101 CssLayoutElement layout = $(CssLayoutElement.class).first();102 // Drag inside the first text field's caption103 TextFieldElement firstTextField = layout.$(TextFieldElement.class).first();104 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(firstTextField, getXOffset(firstTextField, 51), getYOffset(firstTextField, 7)).clickAndHold().moveByOffset((-20), 0).release().perform();105 assertLogText("Mouse dragged in CSSLayout", "1. CSSLayout: left click on This is its caption");106 // Drag from the first text field to the second text field107 TextFieldElement otherTextField = layout.$(TextFieldElement.class).get(1);108 new org.openqa.selenium.interactions.Actions(getDriver()).moveToElement(firstTextField, getXOffset(firstTextField, 51), getYOffset(firstTextField, 27)).clickAndHold().moveToElement(otherTextField, getXOffset(otherTextField, 51), getYOffset(otherTextField, 27)).release().perform();109 assertLogText("Expected the drag to be ignored between elements", "1. CSSLayout: left click on This is its caption");110 }111}...

Full Screen

Full Screen

Source:PageElementActions.java Github

copy

Full Screen

...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()...

Full Screen

Full Screen

Source:MyActions.java Github

copy

Full Screen

...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);...

Full Screen

Full Screen

Source:MouseActions.java Github

copy

Full Screen

...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 with...

Full Screen

Full Screen

Source:AutomationPracticeForm.java Github

copy

Full Screen

...22 WebElement header = driver.findElement(By.className("display-4"));23 Assert.assertEquals(header.getText(),"Automation Pratice Form");24 WebElement firstName = driver.findElement(By.id("inputFirstName3"));25 Actions actions = new Actions(driver);26 Action clickAndHold = actions.clickAndHold(firstName).build();27 clickAndHold.perform();28 Action doubleClick = actions.doubleClick(firstName).build();29 doubleClick.perform();30// WebElement lastName;31// WebElement emailAddress;32// WebElement age;33// WebElement continents;34// WebElement seleniumCommands;35 WebElement fileUpload = driver.findElement(By.cssSelector("input[id='chooseFile']"));36 fileUpload.sendKeys("C:\\Users\\rnicz\\Downloads\\qwerty.txt");37 driver.quit();38 }39}...

Full Screen

Full Screen

Source:B8_LITages_IndianBank.java Github

copy

Full Screen

...35 homepage.click();36 System.out.println("home page entered");37 Deposits=webdriver.findElement(By.xpath(".//*[@id='Menubar1']/li[4]/a"));38 Actions act=new Actions(webdriver);39 act.moveToElement(Deposits).clickAndHold().build().perform();40 //Thread.sleep(1000);41 System.out.println("email goes....mouse");42 43 44 Termdeposit=webdriver.findElement(By.xpath(".//*[@id='Menubar1']/li[4]/ul/li[3]/a"));45 act.moveToElement(Termdeposit).clickAndHold().build().perform();;46 System.out.println("wait");47// 48// headoffice=webdriver.findElement(By.xpath(".//*[@id='Menubar1']/li[8]/ul/li[5]/ul/li[1]/a"));49// act.moveToElement(headoffice).clickAndHold().build().perform();50// System.out.println("1");51 }52} ...

Full Screen

Full Screen

Source:ClickAndHold.java Github

copy

Full Screen

...23 String url = "https://selenium08.blogspot.com/2020/01/click-and-hold.html";24 driver.get(url);25 WebElement titleC = driver.findElement(By.xpath("//li[text()= 'C']"));26 Actions builder = new Actions(driver);27 Action hoveronElement = builder.moveToElement(titleC).build(); // Call clickAndHold() method to perform click and hold operation.28 hoveronElement.perform();29 Action clickAndHold = builder.clickAndHold().build();30 clickAndHold.perform();31 WebElement textSide=driver.findElement(By.xpath("//h3[contains(text(),'Click and Hold in')]"));32 Action moveToAnotherSide = builder.moveToElement(textSide).build();33 moveToAnotherSide.perform();34 }35 @AfterTest36 public void afterTest(){System.out.println("Test Finished Successfully");}37}...

Full Screen

Full Screen

clickAndHold

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.chrome.ChromeDriver;5import org.openqa.selenium.interactions.Actions;6public class ClickAndHold {7public static void main(String[] args) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Admin\\Desktop\\Selenium\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 driver.manage().window().maximize();11 driver.switchTo().frame(0);12 WebElement source = driver.findElement(By.id("draggable"));13 WebElement target = driver.findElement(By.id("droppable"));14 Actions action = new Actions(driver);15 action.clickAndHold(source).moveToElement(target).release().build().perform();16 driver.close();17}18}

Full Screen

Full Screen

clickAndHold

Using AI Code Generation

copy

Full Screen

1package com.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.interactions.Actions;7public class DragAndDrop {8 public static void main(String[] args) {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\sudha\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 driver.manage().window().maximize();12 Actions act = new Actions(driver);13 act.clickAndHold(source).moveToElement(target).release().build().perform();14 }15}16Click to share on Twitter (Opens in new window)17Click to share on Facebook (Opens in new window)18Click to share on LinkedIn (Opens in new window)19Click to share on Pinterest (Opens in new window)20Click to share on Reddit (Opens in new window)21Click to share on Skype (Opens in new window)22Click to share on Telegram (Opens in new window)23Click to share on WhatsApp (Opens in new window)24Click to share on Tumblr (Opens in new window)25Click to share on Pocket (Opens in new window)26Click to print (Opens in new window)27Click to share on StumbleUpon (Opens in new window)28Click to share on Google+ (Opens in new window)29Click to share on Buffer (Opens in new window)30Click to share on Flipboard (Opens in new window)31Click to share on Digg (Opens in new window)32Click to share on Viber (Opens in new window)33Click to share on Weibo (Opens in new window)34Click to share on Xing (Opens in new window)35Click to share on LinkedIn (Opens in new window)36Click to share on Pinterest (Opens in new window)37Click to share on Reddit (Opens in new window)38Click to share on Skype (Opens in new window)39Click to share on Telegram (Opens in new window)40Click to share on WhatsApp (Opens in new window)41Click to share on Tumblr (Opens in new window)42Click to share on Pocket (Opens in new window)43Click to print (Opens

Full Screen

Full Screen

clickAndHold

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.chrome.ChromeDriver;5import org.openqa.selenium.interactions.Actions;6public class DragAndDrop {7public static void main(String[] args) {8System.setProperty("webdriver.chrome.driver","D:\\Selenium\\chromedriver.exe");9WebDriver driver = new ChromeDriver();10driver.get(baseUrl);11Actions act=new Actions(driver);12act.clickAndHold(src).moveToElement(dest).release().build().perform();13}14}

Full Screen

Full Screen

clickAndHold

Using AI Code Generation

copy

Full Screen

1package com.seleniumeasy.tests;2import org.openqa.selenium.By;3import org.openqa.selenium.Keys;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.interactions.Actions;6import org.testng.annotations.Test;7import com.seleniumeasy.pages.DragAndDropPage;8import com.seleniumeasy.pages.HomePage;9import com.seleniumeasy.pages.LeftMenu;10import com.seleniumeasy.testbase.TestBase;11public class DragAndDropTest extends TestBase {12 public void dragAndDrop() throws InterruptedException {13 HomePage homePage = new HomePage(driver);14 homePage.clickOnDemoWebsite();15 LeftMenu leftMenu = new LeftMenu(driver);16 leftMenu.clickOnInputForms();17 leftMenu.clickOnDragAndDrop();18 DragAndDropPage dragAndDropPage = new DragAndDropPage(driver);19 WebElement dragFrom = dragAndDropPage.dragFrom();20 WebElement dragTo = dragAndDropPage.dragTo();21 Actions act = new Actions(driver);22 act.clickAndHold(dragFrom).moveToElement(dragTo).release().perform();23 Thread.sleep(3000);24 }25}26package com.seleniumeasy.pages;27import org.openqa.selenium.By;28import org.openqa.selenium.WebDriver;29import org.openqa.selenium.WebElement;30public class DragAndDropPage {31 WebDriver driver;32 public DragAndDropPage(WebDriver driver) {33 this.driver = driver;34 }35 public WebElement dragFrom() {36 }37 public WebElement dragTo() {38 }39}40package com.seleniumeasy.pages;41import org.openqa.selenium.By;42import org.openqa.selenium.WebDriver;43import org.openqa.selenium.WebElement;44public class HomePage {45 WebDriver driver;46 public HomePage(WebDriver driver) {47 this.driver = driver;48 }49 public WebElement demoWebsite() {50 }51 public void clickOnDemoWebsite() {52 demoWebsite().click();53 }54}55package com.seleniumeasy.pages;56import org.openqa.selenium.By;57import org.openqa.selenium.WebDriver;58import org.openqa.selenium.WebElement;59public class LeftMenu {60 WebDriver driver;61 public LeftMenu(WebDriver driver) {62 this.driver = driver;63 }

Full Screen

Full Screen

clickAndHold

Using AI Code Generation

copy

Full Screen

1Actions action = new Actions(driver);2action.clickAndHold(drag).build().perform();3action.moveToElement(drop).build().perform();4action.release(drop).build().perform();5Actions action = new Actions(driver);6action.dragAndDrop(drag, drop).build().perform();7Actions action = new Actions(driver);8action.dragAndDropBy(drag, 100, 100).build().perform();

Full Screen

Full Screen

clickAndHold

Using AI Code Generation

copy

Full Screen

1Actions action = new Actions(driver);2action.clickAndHold(element).moveByOffset(100, 100).release().build().perform();3Actions action = new Actions(driver);4action.clickAndHold(element).moveToElement(target).release().build().perform();5Actions action = new Actions(driver);6action.clickAndHold(element).moveByOffset(100, 100).release().build().perform();7Actions action = new Actions(driver);8action.clickAndHold(element).moveByOffset(100, 100).release().perform();9Actions action = new Actions(driver);10action.keyDown(element, Keys.CONTROL).sendKeys("a").keyUp(element, Keys.CONTROL).perform();11We can also use the contextClick() method of Actions class

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