{"id":2847,"date":"2020-07-04T16:14:02","date_gmt":"2020-07-04T16:14:02","guid":{"rendered":"https:\/\/codoid.com\/selenium-keys-sendkeys-examples\/"},"modified":"2022-02-04T18:35:14","modified_gmt":"2022-02-04T18:35:14","slug":"selenium-keys-sendkeys-examples","status":"publish","type":"post","link":"https:\/\/codoid.com\/selenium-testing\/selenium-keys-sendkeys-examples\/","title":{"rendered":"Selenium Keys &#038; Sendkeys Examples"},"content":{"rendered":"<p>A major proportion of <a href=\"https:\/\/codoid.com\/automation-testing-services\/\">automation testers<\/a> are familiar with Selenium Keys feature. You can use Selenium Keys and SendKeys in WebElement class, Action Class, and Keyboard class. In this blog article, you will learn the nuances between these methods.<\/p>\n<h3 class=\"widget-title\">WebElement SendKeys<\/h3>\n<p>Everyone is well aware of the fact that SendKeys method is mostly used to enter value in a textbox or file path in File inputbox. Take for instance if you wish to paste the value which is available in clipboard using CTRL + V in a textbox.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntxtBox = driver.find_element_by_id(&quot;txt1&quot;)\r\n\r\n#Pastes the clipboard value in the textbox\r\ntxtBox.send_keys(Keys.LEFT_CONTROL, 'v')\r\n  <\/pre>\n<\/div>\n<p>The above snippet pastes the value in the textbox. Now, you want to enter a string after pasting the clipboard.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntxtBox.send_keys(Keys.LEFT_CONTROL, 'v', 'Codoid')\r\n  <\/pre>\n<\/p><\/div>\n<p>When you execute the above code, it won&#8217;t accept the string (i.e. Codoid). Because the modifiers keys (i.e. CTRL\/ALT\/SHIFT\/etc) will not be released until SendKeys call is complete.<\/p>\n<p>To understand the above precisely,  pass the third argument text as &#8216;value&#8217; and rerun the snippet.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntxtBox.send_keys(Keys.LEFT_CONTROL, 'v', 'value')\r\n<\/pre>\n<\/div>\n<p>If you notice the execution, the snippet has pasted the <a href=\"https:\/\/clipboardjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">clipboard text<\/a> twice. The reason is CTRL key is released only after the SendKeys method call.<\/p>\n<p>CTRL key is not released yet and the third argument (&#8216;value&#8217;) string&#8217;s starting letter is &#8216;v&#8217;. So again CTRL + V is pressed. That&#8217;s why the clipboard text is pasted twice in the textbox.<\/p>\n<p>Then how to enter the argument text in the textbox? Just use <b>KEYS.NULL<\/b> after CTRL + V. Refer the below snippet.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntxtBox.send_keys(Keys.LEFT_CONTROL, 'v', Keys.NULL, 'value')\r\n  <\/pre>\n<\/p><\/div>\n<p>As soon as Keys.NULL is used all the modifier keys will be released.<\/p>\n<h3 class=\"widget-title\">Action Class Sendkeys<\/h3>\n<p>Using Action class&#8217; SendKeys methods, you can&#8217;t press modifier keys. Try the below code, it won&#8217;t paste the clipboard content as we tried using WebElement&#8217;s Sendkeys method.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\naction = ActionChains(driver)\r\n\r\naction.send_keys_to_element(txtBox, Keys.LEFT_CONTROL, &quot;v&quot;).perform()\r\n  <\/pre>\n<\/div>\n<p>You need to use KeyDown to press modifiers keys. Try with the below code, it will paste the text in the textbox.<\/p>\n<div class=\"editor\">\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\naction.key_down(Keys.LEFT_CONTROL).send_keys_to_element(txtBox, &quot;v&quot;).perform()\r\n  <\/pre>\n<\/p><\/div>\n<h3 class=\"widget-title\">In conclusion<\/h3>\n<p>We as an <a href=\"https:\/\/codoid.com\/automation-testing-services\/\">automation testing company<\/a>, have mitigated several unsuccessful automation testing projects. Gaining enduring technical know-how of selenium <b>basics<\/b> to <b>advanced<\/b> level is a key to test automation success.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A major proportion of automation testers are familiar with Selenium Keys feature. You can use Selenium Keys and SendKeys in WebElement class, Action Class, and Keyboard class. In this blog article, you will learn the nuances between these methods. WebElement SendKeys Everyone is well aware of the fact that SendKeys method is mostly used to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[187,179,20],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.3 (Yoast SEO v20.3) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Selenium Keys &amp; Sendkeys Examples - Codoid<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selenium Keys &amp; Sendkeys Examples\" \/>\n<meta property=\"og:description\" content=\"A major proportion of automation testers are familiar with Selenium Keys feature. You can use Selenium Keys and SendKeys in WebElement class, Action Class, and Keyboard class. In this blog article, you will learn the nuances between these methods. WebElement SendKeys Everyone is well aware of the fact that SendKeys method is mostly used to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Codoid\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codoid.softwaretestingcompany\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-04T16:14:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-04T18:35:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codoid.com\/wp-content\/uploads\/2020\/07\/selenium_sendkeys_blog_banner.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codoid\" \/>\n<meta name=\"twitter:site\" content=\"@codoid\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Selenium Keys & Sendkeys Examples - Codoid","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Selenium Keys & Sendkeys Examples","og_description":"A major proportion of automation testers are familiar with Selenium Keys feature. You can use Selenium Keys and SendKeys in WebElement class, Action Class, and Keyboard class. In this blog article, you will learn the nuances between these methods. WebElement SendKeys Everyone is well aware of the fact that SendKeys method is mostly used to [&hellip;]","og_url":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/","og_site_name":"Codoid","article_publisher":"https:\/\/www.facebook.com\/codoid.softwaretestingcompany","article_published_time":"2020-07-04T16:14:02+00:00","article_modified_time":"2022-02-04T18:35:14+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/07\/selenium_sendkeys_blog_banner.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@codoid","twitter_site":"@codoid","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/#article","isPartOf":{"@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/"},"author":{"name":"admin","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586"},"headline":"Selenium Keys &#038; Sendkeys Examples","datePublished":"2020-07-04T16:14:02+00:00","dateModified":"2022-02-04T18:35:14+00:00","mainEntityOfPage":{"@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/"},"wordCount":430,"commentCount":0,"publisher":{"@id":"https:\/\/codoid.com\/#organization"},"articleSection":["Selenium Testing","Fixed","Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/","url":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/","name":"Selenium Keys & Sendkeys Examples - Codoid","isPartOf":{"@id":"https:\/\/codoid.com\/#website"},"datePublished":"2020-07-04T16:14:02+00:00","dateModified":"2022-02-04T18:35:14+00:00","breadcrumb":{"@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-keys-sendkeys-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codoid.com\/"},{"@type":"ListItem","position":2,"name":"Selenium Keys &#038; Sendkeys Examples"}]},{"@type":"WebSite","@id":"https:\/\/codoid.com\/#website","url":"https:\/\/codoid.com\/","name":"Codoid","description":"","publisher":{"@id":"https:\/\/codoid.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codoid.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codoid.com\/#organization","name":"Codoid - Software Testing Company","url":"https:\/\/codoid.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/","url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","contentUrl":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","width":500,"height":500,"caption":"Codoid - Software Testing Company"},"image":{"@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codoid.softwaretestingcompany","https:\/\/twitter.com\/codoid","https:\/\/www.instagram.com\/codoid.softwaretestingcompany\/","https:\/\/www.linkedin.com\/company\/codoid-qacompany","https:\/\/www.pinterest.com\/codoid9282\/codoid-software-testing-company\/","https:\/\/www.youtube.com\/channel\/UCCmOTDQgcf4W8oo22mBMUYA"]},{"@type":"Person","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/codoid.com"]}]}},"_links":{"self":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2847"}],"collection":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/comments?post=2847"}],"version-history":[{"count":5,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2847\/revisions"}],"predecessor-version":[{"id":11513,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2847\/revisions\/11513"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media\/5094"}],"wp:attachment":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media?parent=2847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/categories?post=2847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/tags?post=2847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}