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

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

Source:action.java Github

copy

Full Screen

...47 48 Actions action = new Actions(driver);49 WebElement elementToType = driver.findElement(By.xpath("//*[@id=\"twotabsearchtextbox\"]"));50 Thread.sleep(2000);51 action.sendKeys(elementToType, "watch").build().perform();52 Thread.sleep(2000);53 54 55 WebElement elementToClick = driver.findElement(By.xpath("//*[@id=\"nav-search-submit-button\"]"));56 Thread.sleep(2000);57 58 action.click(elementToClick).build().perform();59 Thread.sleep(2000);60 driver.quit();61 }62 }63 64 65Edureka Action class66 67package action;68import java.util.concurrent.TimeUnit;69import org.openqa.selenium.By;70import org.openqa.selenium.Keys;71import org.openqa.selenium.WebDriver;72import org.openqa.selenium.WebElement;73import org.openqa.selenium.chrome.ChromeDriver;74import org.openqa.selenium.interactions.Actions;75public class edurekaction {76 public static void main(String[] args) throws InterruptedException {77 System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");78 WebDriver driver = new ChromeDriver();79 driver.get("https://www.edureka.co/");80 driver.manage().window().maximize();81 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);82 Actions action= new Actions(driver);83 action.moveToElement(driver.findElement(By.cssSelector("body:nth-child(2) "84 + "nav.navbar.navbar-default.nav_category:nth-child(9) > div.dropdown.dropdown_category_list"85 ))).build().perform();86 Thread.sleep(5000);87 WebElement element1=driver.findElement(By.cssSelector("nav.navbar.navbar-default.nav_category:nth-child(9)"88 + " div.dropdown.dropdown_category_list "89 + "ul.dropdown-menu.dropdown_menu_multi_level.hidden-xs.hidden-sm li.dropdown-submenu.dropdown_submenu_multi:nth-child(9) > "90 + "a.dropdown-toggle.ga_top_category"));91 92 action.moveToElement(element1).build().perform();93 Thread.sleep(2000);94 driver.findElement(By.xpath("//a[contains(text(),'Software Testing')]")).click();95 Thread.sleep(3000);96 driver.quit();97 }98 99}100Google search101package action;102import org.openqa.selenium.By;103import org.openqa.selenium.Keys;104import org.openqa.selenium.WebDriver;105import org.openqa.selenium.WebElement;106import org.openqa.selenium.chrome.ChromeDriver;107import org.openqa.selenium.interactions.Actions;108public class keydemo {109 public static void main(String[] args) throws InterruptedException {110 System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");111 WebDriver driver = new ChromeDriver();112 driver.get("https://www.google.com/");113 driver.manage().window().maximize();114 WebElement element = driver.findElement(By.xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input"));115 116 Actions action = new Actions(driver);117 118 action.keyDown(element,Keys.SHIFT).sendKeys("swaglabs").build().perform();119 Thread.sleep(2000);120 121 driver.quit();122 123 }124}125Login Swag labs ActionClass126package action;127 import org.openqa.selenium.By;128 import org.openqa.selenium.Keys;129 import org.openqa.selenium.WebDriver;130 import org.openqa.selenium.WebElement;131 import org.openqa.selenium.chrome.ChromeDriver;132 import org.openqa.selenium.interactions.Action;133 import org.openqa.selenium.interactions.Actions;134 import org.openqa.selenium.interactions.ClickAction;135 public class logindemo {136 public static void main(String[] args) throws InterruptedException {137 System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");138 WebDriver driver = new ChromeDriver();139 driver.get("https://www.saucedemo.com/");140 driver.manage().window().maximize();141 142 Actions builder = new Actions(driver);143 144 WebElement un = driver.findElement(By.id("user-name"));145 builder.moveToElement(un).build().perform();146 147 148 WebElement pass = driver.findElement(By.id("password"));149 builder.moveToElement(pass).build().perform();150 151 WebElement login =driver.findElement(By.id("login-button"));152 builder.moveToElement(login).build().perform();153 154 155 WebElement drop =driver.findElement(By.id("login-button"));156 builder.moveToElement(login).build().perform();157 Action SeriesOfActions;158 159 SeriesOfActions = (Action) builder160 161 .sendKeys(un,"standard_user")162 .sendKeys(pass,"secret_sauce")163 .keyDown(login, Keys.SHIFT)164 .keyUp(login, Keys.SHIFT)165 .build();166 SeriesOfActions.perform();167 168}169 }170 171 172Ebay search click173 174package action;175import org.openqa.selenium.By;176import org.openqa.selenium.Keys;177import org.openqa.selenium.WebDriver;178import org.openqa.selenium.WebElement;179import org.openqa.selenium.chrome.ChromeDriver;180import org.openqa.selenium.interactions.Actions;181public class ebayclick {182 public static void main(String[] args) throws InterruptedException {183 184 System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");185 WebDriver driver = new ChromeDriver();186 driver.get("https://www.ebay.com/");187 driver.manage().window().maximize();188 189 Actions action = new Actions(driver);190 WebElement elementToType = driver.findElement(By.xpath("//*[@id=\"gh-ac\"]"));191 Thread.sleep(2000);192 action.sendKeys(elementToType, "watch").build().perform();193 Thread.sleep(2000);194 195 196 WebElement elementToClick = driver.findElement(By.xpath("//*[@id=\"gh-btn\"]"));197 Thread.sleep(2000);198 199 action.click(elementToClick).build().perform();200 Thread.sleep(2000);201 //driver.quit();202 }203}204Select Side Pannel205package action;206import java.util.concurrent.TimeUnit;207import org.openqa.selenium.By;208import org.openqa.selenium.WebDriver;209import org.openqa.selenium.WebElement;210import org.openqa.selenium.chrome.ChromeDriver;211import org.openqa.selenium.interactions.Actions;212public class swaglabsaction {213 public static void main(String[] args) throws InterruptedException {214 System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");215 WebDriver driver = new ChromeDriver();216 driver.get("https://www.saucedemo.com/");217 driver.manage().window().maximize();218 driver.findElement(By.id("user-name")).sendKeys("standard_user");219 driver.findElement(By.id("password")).sendKeys("secret_sauce");220 Thread.sleep(2000);221 driver.findElement(By.name("login-button")).click();222 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);223 224 Actions action= new Actions(driver);225 action.moveToElement(driver.findElement(By.xpath("//*[@id=\"react-burger-menu-btn\"]"))).build().perform();226 WebElement elementToClick = driver.findElement(By.xpath("//*[@id=\"react-burger-menu-btn\"]"));227 action.click(elementToClick).build().perform();228 Thread.sleep(2000);229 driver.findElement(By.xpath("//*[@id=\"inventory_sidebar_link\"]")).click();230 Thread.sleep(3000);231 driver.quit();232 }233 234 235 236 237 238 239 240 241 ...

Full Screen

Full Screen

Source:PageElementActions.java Github

copy

Full Screen

...11 * with {@link com.atlassian.pageobjects.elements.PageElement}s. @Inject it into your page objects, or12 * 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

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

Full Screen

Full Screen

Source:MyActions.java Github

copy

Full Screen

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

copy

Full Screen

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

Source:Actions.java Github

copy

Full Screen

...15 16 //WebElement element = driver.findElement(By.name("q"));17 18 //org.openqa.selenium.interactions.Actions ac = new org.openqa.selenium.interactions.Actions(driver);19 //ac.contextClick(element).build().perform();20 21 WebElement doubleelement = driver.findElement(By.name("q"));22 org.openqa.selenium.interactions.Actions ac = new org.openqa.selenium.interactions.Actions(driver);23 ac.doubleClick(doubleelement).build().perform();24 25 26 27 WebElement target_element = driver.findElement(By.linkText("Gmail"));28 org.openqa.selenium.interactions.Actions ac1 = new org.openqa.selenium.interactions.Actions(driver);29 ac.moveToElement(target_element).build().perform();30 ac.moveToElement(target_element).build().perform();31 }32 33 34 35 }36 37 38 39 40 41 42 43 44 ...

Full Screen

Full Screen

Source:action_class.java Github

copy

Full Screen

...10 System.setProperty("webdriver.chrome.driver","D:\\selenium and chrome\\chromedriver.exe" );11 WebDriver driver = new ChromeDriver();12 driver.manage().window().maximize();13driver.get("https:google.com/");14Actions builder = new Actions(driver);15WebElement link_Home = null;16org.openqa.selenium.interactions.Action mouseOverHome = builder17 .moveToElement(link_Home)18 .build();19WebElement fromElement = null;20WebElement toElement = null;21org.openqa.selenium.interactions.Action dragAndDrop = builder.clickAndHold(fromElement)22.moveToElement(toElement)23.release(toElement)24.build();25 }26}...

Full Screen

Full Screen

build

Using AI Code Generation

copy

Full Screen

1package selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.interactions.Actions;6public class ActionsClass {7 public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shubham\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver=new ChromeDriver();10 driver.manage().window().maximize();11 Actions a=new Actions(driver);12 a.dragAndDropBy(driver.findElement(By.id("draggable")), 30, 30).build().perform();13 }14}

Full Screen

Full Screen

build

Using AI Code Generation

copy

Full Screen

1Actions builder = new Actions(driver);2Action dragAndDrop = builder.clickAndHold(draggableElement)3.moveToElement(droppableElement)4.release(droppableElement)5.build();6dragAndDrop.perform();7Actions builder = new Actions(driver);8builder.dragAndDrop(draggableElement, droppableElement).perform();9Actions builder = new Actions(driver);10builder.dragAndDropBy(draggableElement, 10, 10).perform();11Actions builder = new Actions(driver);12builder.clickAndHold(draggableElement)13.moveToElement(droppableElement)14.release(droppableElement)15.perform();16Actions builder = new Actions(driver);17builder.dragAndDrop(draggableElement, droppableElement).perform();

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