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

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

Source:MouseElementActions.java Github

copy

Full Screen

...39 *40 * @return low level interface to control the mouse41 * @deprecated Use the following mapping for updating your code:42 * <p>43 * {@link Mouse#click(Coordinates)} to {@link MouseElementActions#click()}44 * <p>45 * {@link Mouse#doubleClick(Coordinates)} to {@link MouseElementActions#doubleClick()}46 * <p>47 * {@link Mouse#mouseDown(Coordinates)} to {@link MouseElementActions#moveToElement()}48 * then {@link MouseElementActions#clickAndHold()}49 * <p>50 * {@link Mouse#mouseUp(Coordinates)} to {@link MouseElementActions#release()}51 * <p>52 * {@link Mouse#mouseMove(Coordinates)} to {@link MouseElementActions#moveToElement()}53 * <p>54 * {@link Mouse#mouseMove(Coordinates, long, long)} to {@link MouseElementActions#moveToElement(int, int)}55 * <p>56 * {@link Mouse#contextClick(Coordinates)} to {@link MouseElementActions#contextClick()}57 */58 @Deprecated59 public Mouse basic() {60 return ((HasInputDevices) driver).getMouse();61 }62 /**63 * Clicks (without releasing) in the middle of the given element. This is equivalent to:64 * <i>Actions.moveToElement(onElement).clickAndHold()</i>65 *66 * @return this object reference to chain calls67 * @see org.openqa.selenium.interactions.Actions#clickAndHold(WebElement)68 */69 public MouseElementActions clickAndHold() {70 actions().clickAndHold(element).perform();71 return this;72 }73 /**74 * Releases the depressed left mouse button, in the middle of the given element.75 * This is equivalent to:76 * <i>Actions.moveToElement(onElement).release()</i>77 * <p>78 * Invoking this action without invoking {@link #clickAndHold()} first will result in79 * undefined behaviour.80 *81 * @return this object reference to chain calls82 * @see org.openqa.selenium.interactions.Actions#release(WebElement)83 */84 public MouseElementActions release() {85 actions().release(element).perform();86 return this;87 }88 /**89 * Clicks in the middle of the given element. Equivalent to:90 * <i>Actions.moveToElement(onElement).click()</i>91 *92 * @return this object reference to chain calls93 * @see org.openqa.selenium.interactions.Actions#click(WebElement)94 */95 public MouseElementActions click() {96 actions().click(element).perform();97 return this;98 }99 /**100 * Performs a double-click at middle of the given element. Equivalent to:101 * <i>Actions.moveToElement(element).doubleClick()</i>102 *103 * @return this object reference to chain calls104 * @see org.openqa.selenium.interactions.Actions#doubleClick(WebElement)105 */106 public MouseElementActions doubleClick() {107 actions().doubleClick(element).perform();108 return this;109 }110 /**111 * Moves the mouse to the middle of the element. The element is scrolled into view and its112 * location is calculated using getBoundingClientRect.113 *114 * @return this object reference to chain calls115 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement)116 */117 public MouseElementActions moveToElement() {118 actions().moveToElement(element).perform();119 return this;120 }121 /**122 * Moves the mouse to the middle of the target element. The element is scrolled into view and its123 * location is calculated using getBoundingClientRect.124 *125 * @param target element to move to and release the mouse at.126 * @return this object reference to chain calls127 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement)128 */129 public MouseElementActions moveToElement(WebElement target) {130 actions().moveToElement(target).perform();131 return this;132 }133 /**134 * Moves the mouse to an offset from the top-left corner of the element.135 * The element is scrolled into view and its location is calculated using getBoundingClientRect.136 *137 * @param xOffset Offset from the top-left corner. A negative value means coordinates left from138 * the element139 * @param yOffset Offset from the top-left corner. A negative value means coordinates above140 * the element141 * @return this object reference to chain calls142 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement, int, int)143 */144 public MouseElementActions moveToElement(int xOffset, int yOffset) {145 actions().moveToElement(element, xOffset, yOffset).perform();146 return this;147 }148 /**149 * Moves the mouse to an offset from the top-left corner of the target element.150 * The element is scrolled into view and its location is calculated using getBoundingClientRect.151 *152 * @param target element to move to and release the mouse at.153 * @param xOffset Offset from the top-left corner. A negative value means coordinates left from154 * the element155 * @param yOffset Offset from the top-left corner. A negative value means coordinates above156 * the element157 * @return this object reference to chain calls158 * @see org.openqa.selenium.interactions.Actions#moveToElement(WebElement, int, int)159 */160 public MouseElementActions moveToElement(WebElement target, int xOffset, int yOffset) {161 actions().moveToElement(target, xOffset, yOffset).perform();162 return this;163 }164 /**165 * Performs a context-click at middle of the given element. First performs a mouseMove166 * to the location of the element.167 *168 * @return this object reference to chain calls169 * @see org.openqa.selenium.interactions.Actions#contextClick(WebElement)170 */171 public MouseElementActions contextClick() {172 actions().contextClick(element).perform();173 return this;174 }175 /**176 * A convenience method that performs click-and-hold at the location of the source element,177 * moves to the location of this element (target), then releases the mouse.178 *179 * @param source element to emulate button down at180 * @return this object reference to chain calls181 * @see org.openqa.selenium.interactions.Actions#dragAndDrop(WebElement, WebElement)182 */183 public MouseElementActions dragAndDropFrom(WebElement source) {184 actions().dragAndDrop(source, element).perform();185 return this;186 }187 /**188 * A convenience method that performs click-and-hold at the location of this element (source),189 * moves to the location of the target element, then releases the mouse.190 *191 * @param target element to move to and release the mouse at.192 * @return this object reference to chain calls193 * @see org.openqa.selenium.interactions.Actions#dragAndDrop(WebElement, WebElement)194 */195 public MouseElementActions dragAndDropTo(WebElement target) {196 actions().dragAndDrop(element, target).perform();197 return this;198 }199 /**200 * A convenience method that performs click-and-hold at the location of this element,201 * moves by a given offset, then releases the mouse.202 *203 * @param xOffset horizontal move offset.204 * @param yOffset vertical move offset.205 * @return this object reference to chain calls206 * @see org.openqa.selenium.interactions.Actions#dragAndDropBy(WebElement, int, int)207 */208 public MouseElementActions dragAndDropBy(int xOffset, int yOffset) {209 actions().dragAndDropBy(element, xOffset, yOffset).perform();210 return this;211 }212 /**213 * A convenience method that performs click-and-hold at the location of this element,214 * moves by a given offset of target element, then releases the mouse.215 *216 * This Method is not available in pure Selenium217 *218 * @param target element to move to and release the mouse at.219 * @param xOffset horizontal move offset.220 * @param yOffset vertical move offset.221 * @return this object reference to chain calls222 * @see org.openqa.selenium.interactions.Actions#dragAndDropBy(WebElement, int, int)223 */224 public MouseElementActions dragAndDropByWithTargetOffset(WebElement target, int xOffset, int yOffset) {225 actions().clickAndHold(element).moveToElement(target, xOffset, yOffset).release().perform();226 return this;227 }228}...

Full Screen

Full Screen

Source:action.java Github

copy

Full Screen

...15 ((JavascriptExecutor) driver).executeScript("scroll(0,300)");16 driver.findElement(By.id("user-name")).sendKeys("standard_user");17 driver.findElement(By.id("password")).sendKeys("secret_sauce");18 Thread.sleep(2000);19 driver.findElement(By.name("login-button")).click();20 Thread.sleep(2000);21 22 23 Actions ac = new Actions(driver);24 WebElement automate= driver.findElement(By.id("add-to-cart-sauce-labs-backpack"));25 automate.click();26 27 Thread.sleep(2000);28 driver.quit(); 29 }30}31Mouse Click32package action;33 34 import org.openqa.selenium.By;35 import org.openqa.selenium.Keys;36 import org.openqa.selenium.WebDriver;37 import org.openqa.selenium.WebElement;38 import org.openqa.selenium.chrome.ChromeDriver;39 import org.openqa.selenium.interactions.Actions;40 public class click {41 public static void main(String[] args) throws InterruptedException {42 43 System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");44 WebDriver driver = new ChromeDriver();45 driver.get("https://www.amazon.in/");46 driver.manage().window().maximize();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 242 243 ...

Full Screen

Full Screen

Source:GridKeyboardNavigationTest.java Github

copy

Full Screen

...20 public void testCellFocusOnClick() {21 openTestURL();22 GridElement grid = getGridElement();23 Assert.assertTrue("Body cell 0, 0 is not focused on init.", grid.getCell(0, 0).isFocused());24 grid.getCell(5, 2).click();25 Assert.assertFalse("Body cell 0, 0 was still focused after clicking", grid.getCell(0, 0).isFocused());26 Assert.assertTrue("Body cell 5, 2 is not focused after clicking", grid.getCell(5, 2).isFocused());27 }28 @Test29 public void testCellNotFocusedWhenRendererHandlesEvent() {30 openTestURL();31 GridElement grid = getGridElement();32 Assert.assertTrue("Body cell 0, 0 is not focused on init.", grid.getCell(0, 0).isFocused());33 grid.getHeaderCell(0, 3).click();34 Assert.assertFalse("Body cell 0, 0 is focused after click on header.", grid.getCell(0, 0).isFocused());35 Assert.assertTrue("Header cell 0, 3 is not focused after click on header.", grid.getHeaderCell(0, 3).isFocused());36 }37 @Test38 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

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

Full Screen

Full Screen

Source:TreeGridHugeTreeNavigationTest.java Github

copy

Full Screen

...13public class TreeGridHugeTreeNavigationTest extends MultiBrowserTest {14 private TreeGridElement grid;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());...

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

Full Screen

Full Screen

Source:Actions.java Github

copy

Full Screen

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

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

Full Screen

Full Screen

click

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 ClickAction {7 public static void main(String[] args) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Rajesh\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 WebElement search = driver.findElement(By.name("q"));11 Actions act = new Actions(driver);12 act.click(search).perform();13 Thread.sleep(2000);14 act.sendKeys("Selenium").perform();15 Thread.sleep(2000);16 act.sendKeys("17").perform();18 }19}20import org.openqa.selenium.By;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.WebElement;23import org.openqa.selenium.chrome.ChromeDriver;24import org.openqa.selenium.interactions.Actions;25public class ClickAction {26 public static void main(String[] args) throws InterruptedException {27 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Rajesh\\Downloads\\chromedriver_win32\\chromedriver.exe");28 WebDriver driver = new ChromeDriver();29 WebElement link = driver.findElement(By.linkText("Gmail"));30 Actions act = new Actions(driver);31 act.click(link).perform();32 Thread.sleep(2000);33 }34}35import org.openqa

Full Screen

Full Screen

click

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 ClickAction {7public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 WebElement gmail = driver.findElement(By.linkText("Gmail"));11 Actions action = new Actions(driver);12 action.click(gmail).build().perform();13 driver.close();14}15}162. doubleClick() method17public Actions doubleClick(WebElement onElement)18import org.openqa.selenium.By;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebElement;21import org.openqa.selenium.chrome.ChromeDriver;22import org.openqa.selenium.interactions.Actions;23public class DoubleClickAction {24public static void main(String[] args) {25 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");26 WebDriver driver = new ChromeDriver();27 WebElement gmail = driver.findElement(By.linkText("Gmail"));28 Actions action = new Actions(driver);29 action.doubleClick(gmail).build().perform();30 driver.close();31}32}333. moveToElement() method34public Actions moveToElement(WebElement toElement)35import org.openqa.selenium.By;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.WebElement;38import org.openqa.selenium.chrome.ChromeDriver;39import org.openqa.selenium.interactions.Actions;40public class MoveToElementAction {

Full Screen

Full Screen

click

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 Click {8 public static void main(String[] args) {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\vishal mittal\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver=new ChromeDriver();11 WebElement link=driver.findElement(By.linkText("Forgotten account?"));12 Actions action=new Actions(driver);13 action.click(link).build().perform();14 }15}

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1package com.seleniumeasy;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 ActionsClick {8 public static void main(String[] args) throws InterruptedException {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Saurabh Dhingra\\eclipse-workspace\\SeleniumEasy\\Drivers\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 driver.manage().window().maximize();12 Actions act = new Actions(driver);13 act.click(element).build().perform();14 Thread.sleep(3000);15 act.click(element2).build().perform();16 Thread.sleep(2000);17 act.click(element3).build().perform();18 Thread.sleep(2000);19 act.click(element4).build().perform();20 Thread.sleep(2000);21 driver.close();22 }23}

Full Screen

Full Screen

click

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 RightClick {7 public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 Actions action=new Actions(driver);11 action.contextClick(rightClickElement).build().perform();12 driver.close();13 }14}

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");2WebDriver driver = new ChromeDriver();3driver.manage().window().maximize();4Actions actions = new Actions(driver);5WebElement drag = driver.findElement(By.id("draggable"));6actions.clickAndHold(drag).perform();7actions.release(drag).perform();

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.interactions.Actions;6public class ClickMethod {7 public static void main(String args[]) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 Actions a = new Actions(driver);11 WebElement searchBox = driver.findElement(By.name("q"));12 a.click(searchBox).build().perform();13 }14}15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.chrome.ChromeDriver;17import org.openqa.selenium.By;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.interactions.Actions;20public class DoubleClickMethod {21 public static void main(String args[]) throws InterruptedException {22 System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");23 WebDriver driver = new ChromeDriver();24 Actions a = new Actions(driver);25 WebElement searchBox = driver.findElement(By.name("q"));26 a.doubleClick(searchBox).build().perform();27 }28}

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