How to use Actions class of org.openqa.selenium.interactions package

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

Source:GridKeyboardNavigationTest.java Github

copy

Full Screen

...38 public void testSimpleKeyboardNavigation() {39 openTestURL();40 GridElement grid = getGridElement();41 grid.getCell(0, 0).click();42 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_DOWN).perform();43 Assert.assertTrue("Body cell 1, 0 is not focused after keyboard navigation.", grid.getCell(1, 0).isFocused());44 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_RIGHT).perform();45 Assert.assertTrue("Body cell 1, 1 is not focused after keyboard navigation.", grid.getCell(1, 1).isFocused());46 int i;47 for (i = 1; i < 40; ++i) {48 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_DOWN).perform();49 }50 Assert.assertFalse("Grid has not scrolled with cell focus", isElementPresent(By.xpath("//td[text() = '(0, 0)']")));51 Assert.assertTrue("Cell focus is not visible", isElementPresent(By.xpath((("//td[text() = '(" + i) + ", 0)']"))));52 Assert.assertTrue((("Body cell " + i) + ", 1 is not focused"), grid.getCell(i, 1).isFocused());53 }54 @Test55 public void testNavigateFromHeaderToBody() {56 openTestURL();57 GridElement grid = getGridElement();58 grid.scrollToRow(300);59 new org.openqa.selenium.interactions.Actions(driver).moveToElement(grid.getHeaderCell(0, 7)).click().perform();60 grid.scrollToRow(280);61 Assert.assertTrue("Header cell is not focused.", grid.getHeaderCell(0, 7).isFocused());62 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_DOWN).perform();63 Assert.assertTrue("Body cell 280, 7 is not focused", grid.getCell(280, 7).isFocused());64 }65 @Test66 public void testNavigationFromFooterToBody() {67 openTestURL();68 selectMenuPath("Component", "Footer", "Visible");69 GridElement grid = getGridElement();70 grid.scrollToRow(300);71 grid.getFooterCell(0, 2).click();72 Assert.assertTrue("Footer cell does not have focus.", grid.getFooterCell(0, 2).isFocused());73 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_UP).perform();74 Assert.assertTrue("Body cell 300, 2 does not have focus.", grid.getCell(300, 2).isFocused());75 }76 @Test77 public void testNavigateBetweenHeaderAndBodyWithTab() {78 openTestURL();79 GridElement grid = getGridElement();80 grid.getCell(10, 2).click();81 Assert.assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());82 new org.openqa.selenium.interactions.Actions(getDriver()).keyDown(SHIFT).sendKeys(TAB).keyUp(SHIFT).perform();83 Assert.assertTrue("Header cell 0, 2 does not have focus", grid.getHeaderCell(0, 2).isFocused());84 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(TAB).perform();85 Assert.assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());86 // Navigate out of the Grid and try to navigate with arrow keys.87 new org.openqa.selenium.interactions.Actions(getDriver()).keyDown(SHIFT).sendKeys(TAB).sendKeys(TAB).keyUp(SHIFT).sendKeys(ARROW_DOWN).perform();88 Assert.assertTrue("Header cell 0, 2 does not have focus", grid.getHeaderCell(0, 2).isFocused());89 }90 @Test91 public void testNavigateBetweenFooterAndBodyWithTab() {92 openTestURL();93 selectMenuPath("Component", "Footer", "Visible");94 GridElement grid = getGridElement();95 grid.getCell(10, 2).click();96 Assert.assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());97 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(TAB).perform();98 Assert.assertTrue("Footer cell 0, 2 does not have focus", grid.getFooterCell(0, 2).isFocused());99 new org.openqa.selenium.interactions.Actions(getDriver()).keyDown(SHIFT).sendKeys(TAB).keyUp(SHIFT).perform();100 Assert.assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());101 // Navigate out of the Grid and try to navigate with arrow keys.102 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(TAB).sendKeys(TAB).sendKeys(ARROW_UP).perform();103 Assert.assertTrue("Footer cell 0, 2 does not have focus", grid.getFooterCell(0, 2).isFocused());104 }105 @Test106 public void testHomeEnd() throws Exception {107 openTestURL();108 getGridElement().getCell(100, 2).click();109 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(HOME).perform();110 Assert.assertTrue("First row is not visible", getGridElement().getCell(0, 2).isDisplayed());111 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(END).perform();112 Assert.assertTrue("Last row cell not visible", getGridElement().getCell(((GridBasicFeatures.ROWS) - 1), 2).isDisplayed());113 }114 @Test115 public void testPageUpPageDown() throws Exception {116 openTestURL();117 selectMenuPath("Component", "Size", "HeightMode Row");118 getGridElement().getCell(9, 2).click();119 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(PAGE_DOWN).perform();120 Assert.assertTrue("Row 17 did not become visible", isElementPresent(By.xpath("//td[text() = '(17, 2)']")));121 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(PAGE_DOWN).perform();122 Assert.assertTrue("Row 25 did not become visible", isElementPresent(By.xpath("//td[text() = '(25, 2)']")));123 checkFocusedCell(29, 2, 4);124 getGridElement().getCell(41, 2).click();125 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(PAGE_UP).perform();126 Assert.assertTrue("Row 33 did not become visible", isElementPresent(By.xpath("//td[text() = '(33, 2)']")));127 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(PAGE_UP).perform();128 Assert.assertTrue("Row 25 did not become visible", isElementPresent(By.xpath("//td[text() = '(25, 2)']")));129 checkFocusedCell(21, 2, 4);130 }131 @Test132 public void testNavigateOverHiddenColumnToFrozenColumn() {133 openTestURL();134 setFrozenColumns(3);135 toggleColumnHidden(1);136 getGridElement().getCell(0, 2).click();137 assertFocusedCell(0, 2);138 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_LEFT).perform();139 assertFocusedCell(0, 1);140 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(ARROW_LEFT).perform();141 assertFocusedCell(0, 0);142 }143}...

Full Screen

Full Screen

Source:PageElementActions.java Github

copy

Full Screen

1package com.atlassian.pageobjects.elements;2import com.atlassian.webdriver.AtlassianWebDriver;3import org.openqa.selenium.Keys;4import org.openqa.selenium.interactions.Action;5import org.openqa.selenium.interactions.Actions;6import javax.inject.Inject;7import static com.atlassian.pageobjects.elements.WebDriverElement.getWebElement;8/**9 * <p/>10 * Wrapper around WebDriver's {@link org.openqa.selenium.interactions.Actions} class for convenient use11 * 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:TreeGridHugeTreeNavigationTest.java Github

copy

Full Screen

...15 @Test16 public void keyboard_navigation() {17 grid.getRow(0).getCell(0).click();18 // Should navigate to "Granddad 1" and expand it19 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(DOWN, RIGHT).perform();20 Assert.assertEquals(6, grid.getRowCount());21 assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2");22 checkRowFocused(1);23 // Should navigate to and expand "Dad 1/1"24 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(DOWN, DOWN, RIGHT).perform();25 assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1", "Son 1/1/0", "Son 1/1/1", "Son 1/1/2", "Son 1/1/3");26 checkRowFocused(3);27 // Should navigate 100 items down28 Keys[] downKeyArr = new Keys[100];29 for (int i = 0; i < 100; i++) {30 downKeyArr[i] = Keys.DOWN;31 }32 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(downKeyArr).perform();33 WebElement son1_1_99 = findFocusedRow();34 Assert.assertEquals("Son 1/1/99 --", son1_1_99.getText());35 // Should navigate to "Dad 1/1" back36 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(HOME, DOWN, DOWN, DOWN).perform();37 WebElement dad1_1 = findFocusedRow();38 Assert.assertEquals("Dad 1/1 --", dad1_1.getText());39 // Should collapse "Dad 1/1"40 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();41 assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2");42 checkRowFocused(3);43 // Should navigate to "Granddad 1"44 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();45 assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2");46 checkRowFocused(1);47 // Should collapse "Granddad 1"48 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();49 assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Granddad 2");50 checkRowFocused(1);51 // Nothing should happen52 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();53 assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Granddad 2");54 checkRowFocused(1);55 assertNoErrorNotifications();56 }57 @Test58 public void no_exception_when_calling_expand_or_collapse_twice() {59 // Currently the collapsed state is updated in a round trip to the60 // server, thus it is possible to trigger an expand on the same row61 // multiple times through the UI. This should not cause exceptions, but62 // rather ignore the redundant calls.63 grid.getRow(0).getCell(0).click();64 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(RIGHT, RIGHT).perform();65 assertNoErrorNotifications();66 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT, LEFT).perform();67 assertNoErrorNotifications();68 }69 @Test70 public void uncollapsible_item() {71 grid.getRow(0).getCell(0).click();72 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(DOWN, DOWN, RIGHT).perform();73 grid.waitForVaadin();74 // expand Dad 2/175 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(DOWN, DOWN, RIGHT).perform();76 grid.waitForVaadin();77 assertNoErrorNotifications();78 assertCellTexts(5, 0, "Son 2/1/0");79 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();80 grid.waitForVaadin();81 assertNoErrorNotifications();82 assertCellTexts(5, 0, "Son 2/1/0");83 }84 @Test85 public void can_toggle_collapse_on_row_that_is_no_longer_in_cache() {86 grid.getRow(0).getCell(0).click();87 // Expand 2 levels88 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(RIGHT).perform();89 grid.waitForVaadin();90 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(DOWN, RIGHT).perform();91 grid.waitForVaadin();92 grid.scrollToRow(200);93 grid.waitForVaadin();94 // Jump into view95 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();96 grid.waitForVaadin();97 // Collapse98 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(LEFT).perform();99 grid.waitForVaadin();100 Assert.assertEquals(6, grid.getRowCount());101 // Expand102 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(RIGHT, UP).perform();103 grid.waitForVaadin();104 grid.scrollToRow(200);105 new org.openqa.selenium.interactions.Actions(getDriver()).sendKeys(RIGHT).perform();106 grid.waitForVaadin();107 Assert.assertEquals(306, grid.getRowCount());108 }109}

Full Screen

Full Screen

Source:MyActions.java Github

copy

Full Screen

...16import org.openqa.selenium.interactions.MoveMouseAction;17import org.openqa.selenium.interactions.MoveToOffsetAction;18import org.openqa.selenium.interactions.SendKeysAction;19import org.openqa.selenium.internal.Locatable;20public class MyActions {21 protected Mouse mouse;22 protected Keyboard keyboard;23 protected MyCompositeAction action;24 25 public MyActions(WebDriver driver) {26 this(((HasInputDevices)driver).getKeyboard(), ((HasInputDevices)driver).getMouse());27 }28 29 public MyActions(Keyboard keyboard, Mouse mouse) {30 this.mouse = mouse;31 this.keyboard = keyboard;32 resetCompositeAction();33 }34 public MyActions(Keyboard keyboard) {35 this.keyboard = keyboard;36 resetCompositeAction();37 }38 private void resetCompositeAction() {39 action = new MyCompositeAction();40 }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:Actions.java Github

copy

Full Screen

...11import org.openqa.selenium.WebElement;12import org.openqa.selenium.chrome.ChromeDriver;13import org.openqa.selenium.interactions.Action;1415public class Actions {16 static {17 System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");18 // System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");19 }2021 public static void main(String[] args) throws InterruptedException, AWTException {22 // Mouse Hover23 /*24 WebDriver driver=new ChromeDriver(); driver.get("http://www.actitime.com");25 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement26 menu = driver.findElement(By.xpath("//a[.='Features']"));27 org.openqa.selenium.interactions.Actions action=new28 org.openqa.selenium.interactions.Actions(driver);29 action.moveToElement(menu).perform();30 driver.findElement(By.xpath("(//li/a[.='Simple Time Tracking'])[1]")).click() ;31 */32 // ISTQB Mouse Hover33 /*34 WebDriver driver=new ChromeDriver(); driver.get("https://www.istqb.org/");35 driver.manage().window().maximize();36 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement37 menu=driver.findElement(By.xpath("(//a)[@class=' dropdown-toggle'][4]"));38 org.openqa.selenium.interactions.Actions action=new39 org.openqa.selenium.interactions.Actions(driver);40 action.moveToElement(menu).perform();41 driver.findElement(By.linkText("Why ISTQB® Certification?")).click();42 driver.close();43 */4445 // Composite Action46 /*47 WebDriver driver=new ChromeDriver(); driver.get("http://demo.actitime.com");48 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);49 driver.manage().window().maximize(); WebElement menu=50 driver.findElement(By.linkText("actiTIME Inc."));51 org.openqa.selenium.interactions.Actions action=new52 org.openqa.selenium.interactions.Actions(driver);53 action.sendKeys(Keys.CONTROL).click(menu).perform(); Thread.sleep(1000);54 */5556// Context click57 /*WebDriver driver = new ChromeDriver();58 driver.get("http://demo.actitime.com");59 driver.manage().window().maximize();60 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);61 WebElement link = driver.findElement(By.linkText("actiTIME Inc."));62 org.openqa.selenium.interactions.Actions action = new org.openqa.selenium.interactions.Actions(driver);63 action.contextClick(link).perform();64 Robot r = new Robot();65 r.keyPress(KeyEvent.VK_T);66 */676869 // Drag and Drop7071 /*WebDriver driver=new ChromeDriver();72 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);73 driver.get("http://www.dhtmlgoodies.com/submitted-scripts/i-google-like-drag-drop/index.html");74 WebElement src= driver.findElement(By.xpath("//h1[.='Block 2']"));75 WebElement dest= driver.findElement(By.xpath("//h1[.='Block 1']"));76 org.openqa.selenium.interactions.Actions action=new org.openqa.selenium.interactions.Actions(driver);77 action.dragAndDrop(src, dest).perform();78*/ 79//Handling Frames80 /* WebDriver driver=new ChromeDriver();81 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);82 driver.get("https://jqueryui.com/droppable/");83 driver.switchTo().frame(0); 84 WebElement src= driver.findElement(By.id("draggable"));85 WebElement dest=driver.findElement(By.id("droppable"));86 org.openqa.selenium.interactions.Actions action=new org.openqa.selenium.interactions.Actions(driver);87 action.dragAndDrop(src, dest).perform();*/88 89//Handling frames 90 /* WebDriver driver=new ChromeDriver();91 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);92 driver.get("file:///C:/Users/mege/Desktop/page1.html");93 driver.switchTo().frame(0);94 driver.findElement(By.id("t2")).sendKeys("abc");95 driver.switchTo().parentFrame();96 driver.findElement(By.id("t1")).sendKeys("xyz");97*/9899//DoubleClick 100 WebDriver driver=new ChromeDriver();101 driver.get("https://drive.google.com/drive/my-drive");102 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);103 driver.findElement(By.id("identifierId")).sendKeys("niveditasd91@gmail.com");104 Robot r=new Robot();105 r.keyPress(KeyEvent.VK_ENTER);106 driver.findElement(By.name("password")).sendKeys("Megha@91");107 r.keyPress(KeyEvent.VK_ENTER);108 WebElement click = driver.findElement(By.className("l-u-Ab-zb-Pn-ve"));109 org.openqa.selenium.interactions.Actions action=new org.openqa.selenium.interactions.Actions(driver);110 action.doubleClick(click).perform();111 }112} ...

Full Screen

Full Screen

Source:MouseActions.java Github

copy

Full Screen

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

copy

Full Screen

1package org.openqa.selenium.interactions.touch;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.interactions.Actions;5import org.openqa.selenium.interactions.CompositeAction;6import org.openqa.selenium.interactions.HasInputDevices;7import org.openqa.selenium.interactions.HasTouchScreen;8import org.openqa.selenium.interactions.Keyboard;9import org.openqa.selenium.interactions.TouchScreen;10import org.openqa.selenium.internal.Locatable;11public class TouchActions12 extends Actions13{14 protected TouchScreen touchScreen;15 16 public TouchActions(WebDriver driver)17 {18 this(((HasInputDevices)driver).getKeyboard(), ((HasTouchScreen)driver)19 .getTouch());20 }21 22 public TouchActions(Keyboard keyboard, TouchScreen touchScreen) {23 super(keyboard);24 this.touchScreen = touchScreen;25 }26 27 public TouchActions singleTap(WebElement onElement)28 {29 action.addAction(new SingleTapAction(touchScreen, (Locatable)onElement));30 return this;31 }32 33 public TouchActions down(int x, int y)34 {35 action.addAction(new DownAction(touchScreen, x, y));36 return this;37 }38 39 public TouchActions up(int x, int y)40 {41 action.addAction(new UpAction(touchScreen, x, y));42 return this;43 }44 45 public TouchActions move(int x, int y)46 {47 action.addAction(new MoveAction(touchScreen, x, y));48 return this;49 }50 51 public TouchActions scroll(WebElement onElement, int xOffset, int yOffset)52 {53 action.addAction(new ScrollAction(touchScreen, (Locatable)onElement, xOffset, yOffset));54 return this;55 }56 57 public TouchActions doubleTap(WebElement onElement)58 {59 action.addAction(new DoubleTapAction(touchScreen, (Locatable)onElement));60 return this;61 }62 63 public TouchActions longPress(WebElement onElement)64 {65 action.addAction(new LongPressAction(touchScreen, (Locatable)onElement));66 return this;67 }68 69 public TouchActions scroll(int xOffset, int yOffset)70 {71 action.addAction(new ScrollAction(touchScreen, xOffset, yOffset));72 return this;73 }74 75 public TouchActions flick(int xSpeed, int ySpeed)76 {77 action.addAction(new FlickAction(touchScreen, xSpeed, ySpeed));78 return this;79 }80 81 public TouchActions flick(WebElement onElement, int xOffset, int yOffset, int speed)82 {83 action.addAction(new FlickAction(touchScreen, (Locatable)onElement, xOffset, yOffset, speed));84 return this;85 }86}...

Full Screen

Full Screen

Source:Touch_Actions.java Github

copy

Full Screen

...8import org.openqa.selenium.interactions.Locatable;9import org.openqa.selenium.interactions.TouchScreen;10import org.openqa.selenium.interactions.internal.Coordinates;1112public class Touch_Actions {1314 public static void main(String[] args) 15 {16 WebDriver driver=new FirefoxDriver();17 driver.get("https://www.seleniumhq.org/download/");18 driver.manage().window().maximize();19 20 21 //Enable touch actions on automation browser22 TouchScreen touch=((HasTouchScreen)driver).getTouch();23 24 //Identify location at Webpage25 WebElement Element=driver.findElement(By.id("XYZ"));26 //Get Element Coordinates ...

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions action = new Actions(driver);2action.moveToElement(driver.findElement(By.id("id"))).perform();3Actions action = new Actions(driver);4action.moveToElement(driver.findElement(By.id("id"))).perform();5Actions action = new Actions(driver);6action.moveToElement(driver.findElement(By.id("id"))).perform();7Actions action = new Actions(driver);8action.moveToElement(driver.findElement(By.id("id"))).perform();9Actions action = new Actions(driver);10action.moveToElement(driver.findElement(By.id("id"))).perform();11Actions action = new Actions(driver);12action.moveToElement(driver.findElement(By.id("id"))).perform();13Actions action = new Actions(driver);14action.moveToElement(driver.findElement(By.id("id"))).perform();15Actions action = new Actions(driver);16action.moveToElement(driver.findElement(By.id("id"))).perform();17Actions action = new Actions(driver);18action.moveToElement(driver.findElement(By.id("id"))).perform();19Actions action = new Actions(driver);20action.moveToElement(driver.findElement(By.id("id"))).perform();21Actions action = new Actions(driver);22action.moveToElement(driver.findElement(By.id("id"))).perform();23Actions action = new Actions(driver);24action.moveToElement(driver.findElement(By.id("id"))).perform();25Actions action = new Actions(driver);26action.moveToElement(driver.findElement(By.id("id"))).perform();27Actions action = new Actions(driver);28action.moveToElement(driver.findElement(By.id("id"))).perform();29Actions action = new Actions(driver);30action.moveToElement(driver.findElement(By.id("id"))).perform();

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions act=new Actions(driver);2act.dragAndDrop(source, target).perform();3act.clickAndHold(source).perform();4act.release(target).perform();5act.doubleClick(source).perform();6act.clickAndHold(source).perform();7act.release(target).perform();8act.contextClick(source).perform();9act.clickAndHold(source).perform();10act.release(target).perform();11act.doubleClick(source).perform();12act.clickAndHold(source).perform();13act.release(target).perform();14act.contextClick(source).perform();15act.clickAndHold(source).perform();16act.release(target).perform();17act.doubleClick(source).perform();18act.clickAndHold(source).perform();19act.release(target).perform();20act.contextClick(source).perform();21act.clickAndHold(source).perform();22act.release(target).perform();23act.doubleClick(source).perform();24act.clickAndHold(source).perform();25act.release(target).perform();26act.contextClick(source).perform();27act.clickAndHold(source).perform();28act.release(target).perform();29act.doubleClick(source).perform();30act.clickAndHold(source).perform();31act.release(target).perform();32act.contextClick(source).perform();33act.clickAndHold(source).perform();34act.release(target).perform();35act.doubleClick(source).perform();36act.clickAndHold(source).perform();37act.release(target).perform();38act.contextClick(source).perform();

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions actions = new Actions(driver);2actions.moveToElement(webElement).build().perform();3actions.click(webElement).build().perform();4actions.doubleClick(webElement).build().perform();5actions.contextClick(webElement).build().perform();6actions.dragAndDrop(webElement1, webElement2).build().perform();7actions.keyDown(webElement, Keys.CONTROL).build().perform();8actions.keyUp(webElement, Keys.CONTROL).build().perform();9actions.clickAndHold(webElement).build().perform();10actions.release(webElement).build().perform();11actions.sendKeys(webElement, "text").build().perform();12actions.moveToElement(webElement).click().perform();13actions.moveToElement(webElement).build().perform();14actions.click(webElement).build().perform();15actions.doubleClick(webElement).build().perform();16actions.contextClick(webElement).build().perform();17actions.dragAndDrop(webElement1, webElement2).build().perform();18actions.keyDown(webElement, Keys.CONTROL).build().perform();19actions.keyUp(webElement, Keys.CONTROL).build().perform();20actions.clickAndHold(webElement).build().perform();21actions.release(webElement).build().perform();22actions.sendKeys(webElement, "text").build().perform();

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions builder = new Actions(driver);2builder.dragAndDrop(source, target).perform();3Actions builder = new Actions(driver);4builder.clickAndHold(source).moveToElement(target).release().perform();5Actions builder = new Actions(driver);6builder.keyDown(source, Keys.SHIFT).click(target).keyUp(source, Keys.SHIFT).perform();7The above code performs the drag and drop action on the web elements specified in the code. The keyDown() method accepts the

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions a = new Actions(driver);2a.clickAndHold().perform();3a.release().perform();4a.keyDown(Keys.CONTROL).perform();5a.keyUp(Keys.CONTROL).perform();6a.sendKeys("Selenium").perform();7Robot r = new Robot();8r.keyPress(KeyEvent.VK_CONTROL);9r.keyRelease(KeyEvent.VK_CONTROL);10r.mouseMove(100, 100);11r.mousePress(InputEvent.BUTTON1_MASK);12r.mouseRelease(InputEvent.BUTTON1_MASK);13r.mouseWheel(10);14r.waitForIdle();15JavascriptExecutor js = (JavascriptExecutor) driver;16js.executeScript("window.scrollBy(0, 1000)");17js.executeAsyncScript("window.scrollBy(0, 1000)");18WebDriverWait w = new WebDriverWait(driver, 10);19w.until(ExpectedConditions.alertIsPresent());20Alert a = driver.switchTo().alert();21a.accept();22a.dismiss();

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions actions = new Actions(driver);2actions.click(element).perform();3Actions actions = new Actions(driver);4actions.click(element).perform();5Actions actions = new Actions(driver);6actions.click(element).perform();7Actions actions = new Actions(driver);8actions.click(element).perform();9Actions actions = new Actions(driver);10actions.click(element).perform();11Actions actions = new Actions(driver);12actions.click(element).perform();13Actions actions = new Actions(driver);14actions.click(element).perform();15Actions actions = new Actions(driver);16actions.click(element).perform();

Full Screen

Full Screen

Actions

Using AI Code Generation

copy

Full Screen

1Actions act = new Actions(driver);2act.moveToElement(webElement).perform();3act.moveToElement(webElement).click().perform();4act.moveToElement(webElement).click().release().perform();5act.moveToElement(webElement).doubleClick().perform();6act.moveToElement(webElement).contextClick().perform();7act.moveToElement(webElement).clickAndHold().perform();8act.moveToElement(webElement).dragAndDrop(webElement1).perform();9act.moveToElement(webElement).dragAndDropBy(webElement1, 100, 100).perform();10act.moveToElement(webElement).keyDown(Keys.ENTER).perform();11act.moveToElement(webElement).keyUp(Keys.ENTER).perform();12act.moveToElement(webElement).release().perform();13act.moveToElement(webElement).sendKeys("text").perform();14act.moveToElement(webElement).sendKeys(Keys.ENTER).keyDown(Keys.ENTER).keyUp(Keys.ENTER).perform();15act.moveToElement(webElement).sendKeys(Keys.ENTER).keyDown(Keys.ENTER).keyUp(Keys.ENTER).perform();16act.moveToElement(webElement).sendKeys(Keys.ENTER).keyDown(Keys.ENTER).keyUp(Keys.ENTER).perform();17act.moveToElement(webElement).sendKeys(Keys.ENTER).keyDown(Keys.ENTER).keyUp(Keys.ENTER).perform();18act.moveToElement(webElement).sendKeys(Keys.ENTER).keyDown(Keys.ENTER).keyUp(Keys.ENTER).perform();

Full Screen

Full Screen
copy
1a.f(b); <-> b.f(a);2
Full Screen
copy
1static <T> T checkNotNull(T e) {2 if (e == null) {3 throw new NullPointerException();4 }5 return e;6}7
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.

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