{"id":6511,"date":"2020-11-22T15:30:40","date_gmt":"2020-11-22T15:30:40","guid":{"rendered":"https:\/\/codoid.com\/?p=6511"},"modified":"2022-02-04T18:45:28","modified_gmt":"2022-02-04T18:45:28","slug":"selenium-textbox-actions-validations","status":"publish","type":"post","link":"https:\/\/codoid.com\/selenium-testing\/selenium-textbox-actions-validations\/","title":{"rendered":"Selenium TextBox Actions &#038; Validations"},"content":{"rendered":"<p>In Selenium, every HTML object is considered as WebElement. As an automation tester, you should be aware of what are all the applicable actions and validations for each HTML objects. In this blog article, you will learn all Selenium&#8217;s action and validation snippets for TextBox. As per <a href=\"https:\/\/www.w3.org\/TR\/html52\/sec-forms.html#text-typetext-state-and-search-state-typesearch\" target=\"_blank\" rel=\"noopener noreferrer\">W3C<\/a>, a mutable HTML textbox should allow the user to edit value and it should not allow Line Feed &#038; Carriage return characters.<\/p>\n<p>Let&#8217;s start from some basics commands.<\/p>\n<h3>Enter Value<\/h3>\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: java; title: ; notranslate\" title=\"\">\r\nChromeDriver driver = new ChromeDriver();\r\ndriver.get(&quot;URL&quot;);\r\nWebElement txtBox = driver.findElement(By.id(&quot;txt2&quot;));\r\n\r\n\/\/Entering using SendKeys\r\ntxtBox.sendKeys(&quot;codoid&quot;);\r\n\r\n\/\/Entering using JavaScript\r\nexecutor.executeScript(&quot;arguments[0].value=arguments[1]&quot;,txtBox,&quot;codoid&quot;);\r\n<\/pre>\n<\/div>\n<p>Please note that the JavaScript snippet does not mimic user action the way how SendKeys does.<\/p>\n<h3>IsEnabled &#038; ReadOnly<\/h3>\n<p>Before checking whether a textbox is enabled or readonly, you should know what is the difference between disabled and readonly textbox.<\/p>\n<p><b>Readonly<\/b> &#8211; If a textbox is readonly, you can still send the textbox&#8217;s content when a form is submitted and access the textbox using TAB key.<\/p>\n<p><b>Disabled<\/b> &#8211; If a textbox is disabled, the textbox&#8217;s content will not be sent when a form is submitted, you can&#8217;t access the textbox using TAB key, and the events like click, hover, &#038; double click will not be triggered.<\/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: java; title: ; notranslate\" title=\"\">\r\nisReadOnly = txtBox.getAttribute(&quot;readonly&quot;);\r\n\r\nisEnabled = txtBox.isEnabled();\r\n<\/pre>\n<\/div>\n<h3>Retrieve Value<\/h3>\n<p>Retrieving value from a textbox using Selenium is a cake walk for many. However, we, as an <a href=\"https:\/\/codoid.com\/testing-services\/automation-testing-services\/\">automation test company<\/a>, would like to list it here. So that this blog article will be a quick reference guide for software testers  who are learning Selenium.<\/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: java; title: ; notranslate\" title=\"\">\r\nvalue = txtBox.getAttribute(&quot;value&quot;);\r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Selenium, every HTML object is considered as WebElement. As an automation tester, you should be aware of what are all the applicable actions and validations for each HTML objects. In this blog article, you will learn all Selenium&#8217;s action and validation snippets for TextBox. As per W3C, a mutable HTML textbox should allow the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6521,"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,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 TextBox Actions &amp; Validations - 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 TextBox Actions &amp; Validations\" \/>\n<meta property=\"og:description\" content=\"In Selenium, every HTML object is considered as WebElement. As an automation tester, you should be aware of what are all the applicable actions and validations for each HTML objects. In this blog article, you will learn all Selenium&#8217;s action and validation snippets for TextBox. As per W3C, a mutable HTML textbox should allow the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/\" \/>\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-11-22T15:30:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-04T18:45:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codoid.com\/wp-content\/uploads\/2020\/11\/Selenium_TextBox_Actions_-Validations_Blog.png\" \/>\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\/png\" \/>\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=\"1 minute\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Selenium TextBox Actions & Validations - 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 TextBox Actions & Validations","og_description":"In Selenium, every HTML object is considered as WebElement. As an automation tester, you should be aware of what are all the applicable actions and validations for each HTML objects. In this blog article, you will learn all Selenium&#8217;s action and validation snippets for TextBox. As per W3C, a mutable HTML textbox should allow the [&hellip;]","og_url":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/","og_site_name":"Codoid","article_publisher":"https:\/\/www.facebook.com\/codoid.softwaretestingcompany","article_published_time":"2020-11-22T15:30:40+00:00","article_modified_time":"2022-02-04T18:45:28+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/11\/Selenium_TextBox_Actions_-Validations_Blog.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@codoid","twitter_site":"@codoid","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/#article","isPartOf":{"@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/"},"author":{"name":"admin","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586"},"headline":"Selenium TextBox Actions &#038; Validations","datePublished":"2020-11-22T15:30:40+00:00","dateModified":"2022-02-04T18:45:28+00:00","mainEntityOfPage":{"@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/"},"wordCount":299,"commentCount":0,"publisher":{"@id":"https:\/\/codoid.com\/#organization"},"articleSection":["Selenium Testing","Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/","url":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/","name":"Selenium TextBox Actions & Validations - Codoid","isPartOf":{"@id":"https:\/\/codoid.com\/#website"},"datePublished":"2020-11-22T15:30:40+00:00","dateModified":"2022-02-04T18:45:28+00:00","breadcrumb":{"@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codoid.com\/learn\/selenium-testing\/selenium-textbox-actions-validations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codoid.com\/"},{"@type":"ListItem","position":2,"name":"Selenium TextBox Actions &#038; Validations"}]},{"@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\/6511"}],"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=6511"}],"version-history":[{"count":16,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/6511\/revisions"}],"predecessor-version":[{"id":11753,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/6511\/revisions\/11753"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media\/6521"}],"wp:attachment":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media?parent=6511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/categories?post=6511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/tags?post=6511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}