{"id":311,"date":"2021-04-03T12:00:00","date_gmt":"2021-04-03T12:00:00","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/04\/03\/mouse-click-keyboard-event-action-class-in-selenium-webdriver\/"},"modified":"2021-04-03T12:00:00","modified_gmt":"2021-04-03T12:00:00","slug":"mouse-click-keyboard-event-action-class-in-selenium-webdriver","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/2021\/04\/03\/mouse-click-keyboard-event-action-class-in-selenium-webdriver\/","title":{"rendered":"Mouse Click &#038; Keyboard Event: Action Class in Selenium WebDriver"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"311\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>In this article we will check how to handle Keyboard and Mouse event in Selenium WebDriver.<\/p>\n<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper tve-toc tve-elem-scroll tve-toc-expandable show-icon tcb-icon-display tcb-local-vars-root\" data-animation=\"slide\" data-animation-speed=\"slow\" data-bullet-style='{\"0\":\"tve-u-17399bf2913\",\"1\":\"tve-u-17399c228ad\",\"2\":\"tve-u-17399c282f4\"}' data-columns=\"1\" data-columns-d=\"1\" data-css=\"tve-u-17897653f18\" data-ct=\"toc-60696\" data-ct-name=\"Table of Contents 12\" data-element-name=\"Table of Contents\" data-headers=\"h1,h3,h5\" data-heading-style='{\"0\":\"tve-u-17897653f20\",\"1\":\"tve-u-17897653f22\",\"2\":\"tve-u-17897653f24\"}' data-highlight=\"progressive\" data-number-style='{\"0\":\"tve-u-17897653f21\",\"1\":\"tve-u-17897653f23\",\"2\":\"tve-u-17897653f25\"}' data-numbering=\"advanced\" data-state-default=\"expanded\" data-transition=\"none\" style=\"\">\n<div class=\"thrive-colors-palette-config\" style=\"display: none !important\"><\/div>\n<p><svg class=\"toc-icons\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-0\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-1\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-2\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><\/svg><\/p>\n<div class=\"tve-toc-divider\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\">\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgba(0, 0, 0, 0.08)\" data-css=\"tve-u-17897653f19\" data-style=\"tve_sep-1\" data-thickness-d=\"1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<div class=\"tve-content-box-background\" data-css=\"tve-u-17897653f1a\"><\/div>\n<div class=\"thrv_wrapper tve-toc-title tve-toc-hidden reverse show-icon tcb-icon-display tve-no-dropzone tve-prevent-content-edit\" data-css=\"tve-u-17897653f1b\" style=\"\">\n<div class=\"tve-content-box-background\" style=\"\"><\/div>\n<div class=\"tve-cb\" style=\"\">\n<div class=\"tve-toc-title-icon\" data-icon-code=\"icon-caret-right-solid\" style=\"\"><svg class=\"tcb-icon\" data-id=\"icon-caret-right-solid\" data-name=\"\" viewbox=\"0 0 192 512\">\n<path d=\"M0 384.662V127.338c0-17.818 21.543-26.741 34.142-14.142l128.662 128.662c7.81 7.81 7.81 20.474 0 28.284L34.142 398.804C21.543 411.404 0 402.48 0 384.662z\"><\/path>\n<\/svg><\/div>\n<div class=\"thrv_wrapper thrv_text_element tve_no_icons\" data-css=\"tve-u-17897653f1c\" style=\"\">\n<div class=\"tcb-plain-text\" data-css=\"tve-u-17897653f1d\" style=\"\">Table Of Contents<\/div>\n<\/p><\/div>\n<\/div>\n<\/div>\n<div class=\"tve-cb tve-toc-content tve-prevent-content-edit\" style=\"\">\n<div class=\"thrv_wrapper tve-toc-list tcb-no-delete tcb-no-save tcb-no-clone tve-no-dropzone\" data-css=\"tve-u-17897653f1e\" style=\"\">\n<div class=\"tve-content-box-background\" data-css=\"tve-u-17897653f1f\" data-tcb_hover_state_parent=\"1\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"tve_ct_content tve_clearfix\">\n<div class=\"ct_column\">\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17897653f22\" data-element-name=\"Heading Level 2\" data-tag=\"H3\">\n<div class=\"thrv_wrapper tve-toc-number tve-toc-number1 tve_no_icons tve-jump-scroll\" data-css=\"tve-u-17897653f23\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1617447518096\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.1<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1617447518096\" jump-animation=\"smooth\">Action Class in Selenium<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17897653f22\" data-element-name=\"Heading Level 2\" data-tag=\"H3\">\n<div class=\"thrv_wrapper tve-toc-number tve-toc-number1 tve_no_icons tve-jump-scroll\" data-css=\"tve-u-17897653f23\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1617447518097\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.2<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1617447518097\" jump-animation=\"smooth\">Handling Keyboard &amp; Mouse Events<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17897653f22\" data-element-name=\"Heading Level 2\" data-tag=\"H3\">\n<div class=\"thrv_wrapper tve-toc-number tve-toc-number1 tve_no_icons tve-jump-scroll\" data-css=\"tve-u-17897653f23\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1617447518098\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.3<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1617447518098\" jump-animation=\"smooth\">Summary<\/a><\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgba(0, 0, 0, 0.08)\" data-css=\"tve-u-17897653f19\" data-style=\"tve_sep-1\" data-thickness-d=\"1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1617447518096\"><strong>Action Class in Selenium<\/strong><\/h3>\n<p><strong>Action Class in Selenium<\/strong> is a built-in feature provided by the selenium for handling keyboard and mouse events. It includes various operations such as multiple events clicking by control key, drag and drop events and many more. These operations from the action class are performed using the advanced user interaction API in Selenium WebDriver.<\/p>\n<p>Using this we can do many actions in test scripts that we normally do with keyboard and mouse.<\/p>\n<h3 class=\"\" id=\"t-1617447518097\"><strong>Handling Keyboard &amp; Mouse Events<\/strong><\/h3>\n<p>Handling special keyboard and mouse events are done using the Advanced User Interactions API. It contains the Actions and the Action classes that are needed when executing these events. The following are the most used keyboard and mouse events provided by the Actions class.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_table tcb-fixed tcb-mobile-table\" data-css=\"tve-u-178976982fc\" data-ct=\"table-39165\" data-ct-name=\"Blue Shades\" data-element-name=\"Table\">\n<table class=\"tve_table tcb-fixed tve_table_flat\" data-cols=\"2\" data-css=\"tve-u-178976982fd\" data-rows=\"12\">\n<thead data-css=\"tve-u-178976982fe\">\n<tr class=\"tve_table_row\">\n<th class=\"tve_table_cell\" colspan=\"1\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-178976b0e02\">\n<p data-css=\"tve-u-178976b0deb\"><strong>Method<\/strong><\/p>\n<\/div>\n<\/th>\n<th class=\"tve_table_cell\" colspan=\"1\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<p data-css=\"tve-u-178976b4480\"><strong>Description<\/strong><\/p>\n<\/div>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody data-css=\"tve-u-17897698306\">\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" data-css=\"tve-u-17897698307\" data-th=\"\tMethod\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>clickAndHold()<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" data-css=\"tve-u-1789769830a\" data-th=\"\tDescription\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Clicks (without releasing) at the current mouse location.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" data-css=\"tve-u-1789769830f\" data-th=\"\tMethod\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>contextClick()<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" data-css=\"tve-u-17897698310\" data-th=\"\tDescription\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Performs a context-click at the current mouse location. (Right Click Mouse Action)<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" data-css=\"tve-u-17897698314\" data-th=\"\tMethod\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>doubleClick()<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" data-css=\"tve-u-17897698315\" data-th=\"\tDescription\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Performs a double-click at the current mouse location.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e290\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>dragAndDrop(source, target)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2af\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<p>source- element to emulate button down at.<\/p>\n<p>target- element to move to and release the mouse at.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e293\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>dragAndDropBy(source, x-offset, y-offset)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2b0\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.<\/p>\n<p><strong>Parameters<\/strong>:<\/p>\n<p>source- element to emulate button down at.<\/p>\n<p>xOffset- horizontal move offset.<\/p>\n<p>yOffset- vertical move offset.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e294\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>keyDown(modifier_key)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2b2\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Performs a modifier key press. Does not release the modifier key &#8211; subsequent interactions may assume it&#8217;s kept pressed.<\/p>\n<p><strong>Parameters<\/strong>:<\/p>\n<p>modifier_key &#8211; any of the modifier keys (Keys.ALT, Keys.SHIFT, or Keys.CONTROL)<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e296\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>keyUp(modifier _key)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2b4\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Performs a key release.<\/p>\n<p><strong>Parameters<\/strong>:<\/p>\n<p>modifier_key &#8211; any of the modifier keys (Keys.ALT, Keys.SHIFT, or Keys.CONTROL)<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e298\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>moveByOffset(x-offset, y-offset)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2b6\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Moves the mouse from its current position (or 0,0) by the given offset.<\/p>\n<p><strong>Parameters<\/strong>:<\/p>\n<p>x-offset- horizontal offset. A negative value means moving the mouse left.<\/p>\n<p>y-offset- vertical offset. A negative value means moving the mouse down.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e29a\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>moveToElement(toElement)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2b8\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Moves the mouse to the middle of the element.<\/p>\n<p><strong>Parameters<\/strong>:<\/p>\n<p>toElement- element to move to.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e29c\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>release()<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789770e2ba\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Releases the depressed left mouse button at the current mouse location<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr class=\"tve_table_row\">\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-17897698319\" data-th=\"\tMethod\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\"><strong>sendKeys(onElement, charsequence)<\/strong><\/p>\n<\/div>\n<\/td>\n<td class=\"tve_table_cell\" colspan=\"1\" data-css=\"tve-u-1789769831a\" data-th=\"\tDescription\" rowspan=\"1\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897698308\">\n<p data-css=\"tve-u-17897698309\">Sends a series of keystrokes onto the element.<\/p>\n<p><strong>Parameters<\/strong>:<\/p>\n<p>onElement &#8211; element that will receive the keystrokes, usually a text field<\/p>\n<p>charsequence &#8211; any string value representing the sequence of keystrokes to be sent<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Let us consider following <strong>moveToElement()<\/strong> method to understand <strong>Actions class<\/strong> of Selenium WebDriver.<\/p>\n<p>Let us automate following scenario to understand it better.<\/p>\n<ul>\n<li>Open the URL : <a class=\"tve-froala\" href=\"https:\/\/rahulshettyacademy.com\/AutomationPractice\/\" style=\"outline: none;\">https:\/\/rahulshettyacademy.com\/AutomationPractice\/<\/a><\/li>\n<li>Create object of <strong>Actions <\/strong>class and perform mouse over action.<\/li>\n<li>Click on option <strong>Reload <\/strong>to perform action on that hyper link.<\/li>\n<\/ul>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17897723f83\" style=\"\">\n<p data-css=\"tve-u-1789772cd36\" style=\"\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.WebElement;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<br \/>import org.openqa.selenium.interactions.Actions;<\/p>\n<p>public class ActionsTest {<\/p>\n<p>\u00a0\u00a0\u00a0 public static void main(String[] args) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<em>setProperty<\/em>(&#8220;webdriver.chrome.driver&#8221;, &#8220;C:\\chromedriver.exe&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebDriver driver = new ChromeDriver();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/code to maximize chrome browser<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.manage().window().maximize();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String baseURL = &#8220;https:\/\/rahulshettyacademy.com\/AutomationPractice\/&#8221;;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(baseURL);<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Code to perform mouse hover on button by the text Mouse Hover<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Actions actions = new Actions(driver);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement mouseHover =\u00a0 driver.findElement(By.<em>id<\/em>(&#8220;mousehover&#8221;));<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 actions.moveToElement(mouseHover).build().perform();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.findElement(By.<em>linkText<\/em>(&#8220;Reload&#8221;)).click();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Close chrome driver.<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.close();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Let us consider example for <strong>KeyDown<\/strong> feature of <strong>Actions<\/strong> Class.<\/p>\n<p>Let us automate following scenario to understand it better.<\/p>\n<ul>\n<li>Open the URL :\u00a0<a class=\"tve-froala\" href=\"https:\/\/www.amazon.in\/\" style=\"outline: none;\">https:\/\/www.amazon.in\/<\/a><\/li>\n<li>Create object of <strong>Actions <\/strong>class.<\/li>\n<li>Inspect <strong>search box<\/strong> and search for keyword \u201cSamsung\u201d<\/li>\n<\/ul>\n<p>We will search Samsung key word using Actions class and KeyDown method of Actions class.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1789773996a\" style=\"\">\n<p data-css=\"tve-u-17897741697\" style=\"\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.Keys;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.WebElement;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<br \/>import org.openqa.selenium.interactions.Actions;<\/p>\n<p>public class ActionsKeyDown {<br \/>\u00a0\u00a0\u00a0 public static void main(String[] args) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0System.<em>setProperty<\/em>(&#8220;webdriver.chrome.driver&#8221;, &#8220;C:\\chromedriver.exe&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebDriver driver = new ChromeDriver();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/code to maximize chrome browser<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.manage().window().maximize();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String baseURL = &#8220;https:\/\/www.amazon.in\/&#8221;;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(baseURL);<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Actions actions = new Actions(driver);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement searchBox = driver.findElement(By.<em>id<\/em>(&#8220;twotabsearchtextbox&#8221;));<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 actions.moveToElement(searchBox).click().keyDown(Keys.<em>SHIFT<\/em>).sendKeys(&#8220;Samsung&#8221;).build().perform();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Close chrome driver<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.close();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Let us consider example to perform right click on element on web page.<\/p>\n<ul>\n<li>Open the URL :\u00a0<a href=\"https:\/\/rahulshettyacademy.com\/AutomationPractice\/\">https:\/\/rahulshettyacademy.com\/AutomationPractice\/<\/a><\/li>\n<li>Inspect web element of \u201cMouse Hover\u201d<\/li>\n<li>Create object of Actions class and perform right click using \u201ccontextClick\u201d<\/li>\n<\/ul>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1789774f586\" style=\"\">\n<p data-css=\"tve-u-17897754a2c\" style=\"\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.WebElement;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<br \/>import org.openqa.selenium.interactions.Actions;<\/p>\n<p>public class ActionsTest {<\/p>\n<p>\u00a0\u00a0\u00a0 public static void main(String[] args) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<em>setProperty<\/em>(&#8220;webdriver.chrome.driver&#8221;, &#8220;C:\\chromedriver.exe&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebDriver driver = new ChromeDriver();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/code to maximize chrome browser<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.manage().window().maximize();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String baseURL = &#8220;https:\/\/rahulshettyacademy.com\/AutomationPractice\/&#8221;;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(baseURL);<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Code to perform mouse hover on button by the text Mouse Hover<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Actions actions = new Actions(driver);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement mouseHover =\u00a0 driver.findElement(By.<em>id<\/em>(&#8220;mousehover&#8221;));<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/code to perform right click on particular element<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 actions.moveToElement(mouseHover).contextClick().build().perform();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Close chrome driver.<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.close();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1617447518098\"><strong>Summary<\/strong><\/h3>\n<ul type=\"disc\">\n<li>Handling special keyboard and mouse events are done using the AdvancedUserInteractions API.<\/li>\n<li>Frequently used Keyword and Mouse Events are doubleClick(), keyUp, dragAndDropBy, contextClick &amp; sendKeys.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<p><!-- AI CONTENT END 1 --><br \/>\n<\/section>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we will check how to handle Keyboard and Mouse event in Selenium WebDriver. Table Of Contents 0.1 Action Class in Selenium 0.2 Handling Keyboard &amp; Mouse Events 0.3 Summary Action Class in Selenium Action Class in Selenium is a built-in feature provided by the selenium for handling keyboard and mouse events. It [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-311","post","type-post","status-publish","format-standard","hentry","category-selenium","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}