{"id":256,"date":"2020-12-25T12:00:00","date_gmt":"2020-12-25T12:00:00","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2020\/12\/25\/selenium-form-webelement-textbox-submit-button-sendkeys-click\/"},"modified":"2020-12-25T12:00:00","modified_gmt":"2020-12-25T12:00:00","slug":"selenium-form-webelement-textbox-submit-button-sendkeys-click","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/2020\/12\/25\/selenium-form-webelement-textbox-submit-button-sendkeys-click\/","title":{"rendered":"Selenium Form WebElement: TextBox, Submit Button, sendKeys(), Click()"},"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=\"256\" id=\"tve_editor\">\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-bullet-style='{\"0\":\"tve-u-1739a1489c2\",\"1\":\"tve-u-1739a14bf0e\",\"2\":\"tve-u-1739a14c947\"}' data-columns=\"1\" data-columns-d=\"1\" data-css=\"tve-u-1769915bce7\" data-ct=\"toc-60692\" data-ct-name=\"Table of Contents 11\" data-element-name=\"Table of Contents\" data-headers=\"h1,h3,h5\" data-heading-style='{\"0\":\"tve-u-1769915bcee\",\"1\":\"tve-u-1769915bcf0\",\"2\":\"tve-u-1769915bcf2\"}' data-highlight=\"progressive\" data-number-style='{\"0\":\"tve-u-1769915bcef\",\"1\":\"tve-u-1769915bcf1\",\"2\":\"tve-u-1769915bcf3\"}' data-numbering=\"advanced\" data-state-default=\"collapsed\" data-state-default-d=\"expanded\" data-transition=\"fade\" 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-chevron-right-solid\" id=\"toc-bullet-0\" viewbox=\"0 0 320 512\"><path d=\"M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z\"><\/path><\/symbol><symbol data-id=\"icon-chevron-right-solid\" id=\"toc-bullet-1\" viewbox=\"0 0 320 512\"><path d=\"M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z\"><\/path><\/symbol><symbol data-id=\"icon-chevron-right-solid\" id=\"toc-bullet-2\" viewbox=\"0 0 320 512\"><path d=\"M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z\"><\/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=\"rgb(217, 217, 217)\" data-css=\"tve-u-1769915bce8\" data-style=\"tve_sep-1\" data-style-d=\"tve_sep-4\" data-thickness-d=\"2\">\n<hr class=\"tve_sep tve_sep-4\" style=\"\"\/><\/div>\n<\/div>\n<div class=\"tve-content-box-background\" data-css=\"tve-u-1769915bce9\" style=\"\"><\/div>\n<div class=\"thrv_wrapper tve-toc-title reverse show-icon tve-no-dropzone tve-prevent-content-edit\" data-css=\"tve-u-1769915bcea\" data-tcb_hover_state_parent=\"\" style=\"border-top-left-radius: 10px !important; border-top-right-radius: 10px !important;\">\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-ellipsis-h-solid\" style=\"\"><svg class=\"tcb-icon\" data-id=\"icon-ellipsis-h-solid\" data-name=\"\" viewbox=\"0 0 512 512\"><path d=\"M328 256c0 39.8-32.2 72-72 72s-72-32.2-72-72 32.2-72 72-72 72 32.2 72 72zm104-72c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72zm-352 0c-39.8 0-72 32.2-72 72s32.2 72 72 72 72-32.2 72-72-32.2-72-72-72z\"><\/path><\/svg><\/div>\n<div class=\"thrv_wrapper thrv_text_element tve_no_icons\" style=\"overflow: hidden; border-radius: 0px !important;\">\n<div class=\"tcb-plain-text\" data-css=\"tve-u-1769915bceb\" 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-1769915bcec\" style=\"\">\n<div class=\"tve-content-box-background\" data-css=\"tve-u-1769915bced\" 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-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922953\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.1<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922953\" jump-animation=\"smooth\">What are Form WebElement?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922954\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.2<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922954\" jump-animation=\"smooth\">Introduction to WebElement, findElement(), findElements() <\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922955\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.3<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922955\" jump-animation=\"smooth\">Input Box<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922956\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.4<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922956\" jump-animation=\"smooth\">sendKeys in Selenium<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1769915bcf2\" data-element-name=\"Heading Level 3\" data-tag=\"H5\">\n<div class=\"thrv_wrapper tve-toc-number tve-toc-number2 tve_no_icons tve-jump-scroll\" data-css=\"tve-u-1769915bcf3\" data-element-name=\"Number Level 3\" data-level=\"2\" data-target=\"#t-1608886922959\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.4.1<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922959\" jump-animation=\"smooth\">Entering values in Input Boxes<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922957\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.5<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922957\" jump-animation=\"smooth\">Deleting values in input boxes<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922958\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.6<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922958\" jump-animation=\"smooth\">Buttons<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1769915bcf2\" data-element-name=\"Heading Level 3\" data-tag=\"H5\">\n<div class=\"thrv_wrapper tve-toc-number tve-toc-number2 tve_no_icons tve-jump-scroll\" data-css=\"tve-u-1769915bcf3\" data-element-name=\"Number Level 3\" data-level=\"2\" data-target=\"#t-1608886922960\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.6.1<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922960\" jump-animation=\"smooth\">Submit buttons<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922961\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.7<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922961\" jump-animation=\"smooth\">Complete Code<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1769915bcf0\" 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-1769915bcf1\" data-element-name=\"Number Level 2\" data-level=\"1\" data-target=\"#t-1608886922962\" jump-animation=\"smooth\"><span class=\"tve-toc-disabled\">0.8<\/span><\/div>\n<p><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1608886922962\" jump-animation=\"smooth\">Summary<\/a><\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgb(217, 217, 217)\" data-css=\"tve-u-1769915bce8\" data-style=\"tve_sep-1\" data-style-d=\"tve_sep-4\" data-thickness-d=\"2\">\n<hr class=\"tve_sep tve_sep-4\" 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-1608886922953\">What are Form WebElement?<\/h3>\n<p>Forms are the fundamental web elements to receive information from the website visitors. Web forms have different GUI elements like Text boxes, Password fields, Checkboxes, Radio buttons, dropdowns, file inputs, etc.<\/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<p>We will see how to access these different form elements using Selenium Web Driver with Java. <strong>Selenium <\/strong>encapsulates every form element as an object of WebElement. It provides API to find the elements and act on them like entering text into text boxes, clicking the buttons, etc. We will see the methods that are available to access each form element.<\/p>\n<p>In this tutorial, we will see how to identify the following form elements<\/p>\n<ul class=\"\" type=\"disc\">\n<li>Introduction to WebElement, findElement(), findElements()<\/li>\n<li>Input Box<\/li>\n<li>Entering Values in Input Boxes<\/li>\n<li>Deleting Values in Input Boxes<\/li>\n<li>Buttons<\/li>\n<li>Submit Buttons<\/li>\n<li>Complete Code<\/li>\n<\/ul>\n<h3 class=\"\" id=\"t-1608886922954\"><strong>Introduction to WebElement, findElement(), findElements() <\/strong><\/h3>\n<p>Selenium Web Driver encapsulates a simple form element as an object of <strong>WebElement. <\/strong>There are various techniques by which the WebDriver identifies the form elements based on the different properties of the Web elements like ID, Name, Class, XPath, Tagname, CSS Selectors, link Text, etc.<\/p>\n<p>Web Driver provides the following two methods to find the elements.<\/p>\n<ul class=\"\" type=\"disc\">\n<li><strong>findElement()<\/strong> \u2013 finds a single web element and returns as a WebElement object.<\/li>\n<li><strong>findElements()<\/strong> \u2013 returns a list of WebElement objects matching the locator criteria.<\/li>\n<\/ul>\n<p>Let\u2019s see a simple code to understand findElement() to identify text field using WebElement.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\" data-css=\"tve-u-17699254ed5\" style=\"\">\n<div class=\"tve-content-box-background\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17699291b2a\" style=\"\">\n<p data-css=\"tve-u-176992481a8\" style=\"\"><span style=\"color: rgb(255, 255, 255);\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p>public class WebElementFindElement {<\/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;Chrome exe path&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebDriver driver = new ChromeDriver();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.manage().window().maximize();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(&#8220;https:\/\/rahulshettyacademy.com\/AutomationPractice\/&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Code to find element using id and send values in text field.<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.findElement(By.<em>id<\/em>(&#8220;name&#8221;)).sendKeys(&#8220;Rahul Shetty&#8221;);<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 \/>}<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1608886922955\"><strong>Input Box<\/strong><\/h3>\n<p>Input boxes refer to either of these two types:<\/p>\n<ol start=\"1\" type=\"1\">\n<li><strong>Text Fields<\/strong>&#8211; text boxes that accept typed values and show them as they are.<\/li>\n<li><strong>Password Fields<\/strong>&#8211; text boxes that accept typed values but mask them as a series of special characters (commonly dots and asterisks) to avoid sensitive values to be displayed.<\/li>\n<\/ol>\n<p>Let us see a simple code to understand Input box for text fields and password fields.<\/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\" data-css=\"tve-u-17699298425\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1769928dc68\" style=\"\">\n<p data-css=\"tve-u-1769927d322\"><span style=\"color: rgb(255, 255, 255);\"><br \/>package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p>public class InputBoxDemo {<\/p>\n<p>public static void main(String[] args) {<br \/>System.setProperty(&#8220;webdriver.chrome.driver&#8221;, &#8220;Chrome exe path&#8221;);<br \/>WebDriver driver = new ChromeDriver();<br \/>driver.manage().window().maximize();<\/p>\n<p>driver.get(&#8220;https:\/\/www.facebook.com\/&#8221;);<br \/>\/\/Code to find element using id and send values in text field.<br \/>driver.findElement(By.id(&#8220;email&#8221;)).sendKeys(&#8220;Rahul Shetty@rahulshettyacademy.com&#8221;);<br \/>driver.findElement(By.id(&#8220;pass&#8221;)).sendKeys(&#8220;123456789&#8221;);<br \/>\/\/Close chrome driver<br \/>driver.close();<br \/>\u00a0 \u00a0 \u00a0 \u00a0}<br \/>}<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element tve-froala fr-box fr-basic\">\n<h3 class=\"\" id=\"t-1608886922956\"><strong>sendKeys in Selenium<\/strong><\/h3>\n<p><strong>sendkeys() in Selenium<\/strong> is a method used to enter editable content in the text and password fields during test execution. These fields are identified using locators like name, class, id, etc. It is a method available on the web element. Unlike the type method, sendkeys() method does not replace existing text in any text box.<\/p>\n<h5 class=\"\" id=\"t-1608886922959\"><strong><u>Entering values in Input Boxes<\/u><\/strong><\/h5>\n<p>To enter text into the Text Fields and Password Fields, sendKeys() is the method available on the WebElement.<\/p>\n<p>Using the same example of <a class=\"tve-froala\" href=\"https:\/\/www.facebook.com\/\" style=\"outline: none;\">https:\/\/www.facebook.com\/<\/a> site, here is how we find the Text field and Password fields and enter values into them.<\/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\" data-css=\"tve-u-176992ae285\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-176992aca7e\" style=\"\">\n<p data-css=\"tve-u-176992a9576\"><span style=\"color: rgb(255, 255, 255);\"><br \/>package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p>public class InputBoxDemo {<\/p>\n<p>public static void main(String[] args) {<br \/>System.setProperty(&#8220;webdriver.chrome.driver&#8221;, &#8220;Chrome exe path&#8221;);<br \/>WebDriver driver = new ChromeDriver();<br \/>driver.manage().window().maximize();<\/p>\n<p>driver.get(&#8220;https:\/\/www.facebook.com\/&#8221;);<br \/>\/\/Code to find element using id and send values in text field.<br \/>driver.findElement(By.id(&#8220;email&#8221;)).sendKeys(&#8220;Rahul Shetty@rahulshettyacademy.com&#8221;);<br \/>driver.findElement(By.id(&#8220;pass&#8221;)).sendKeys(&#8220;123456789&#8221;);<br \/>\/\/Close chrome driver<br \/>driver.close();<br \/>\u00a0 \u00a0 }<br \/>}<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1608886922957\"><strong>Deleting values in input boxes<\/strong><\/h3>\n<p>The <strong>clear()<\/strong> method is used to delete the text in an input box. <strong>This method does not need a parameter<\/strong>. The code snippet below will clear out the text from the Email or Password fields.<\/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\" data-css=\"tve-u-176992e63cc\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-176992d03fd\" style=\"\">\n<p data-css=\"tve-u-176992e15be\" style=\"\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p>public class InputBoxDemo {<\/p>\n<p>public static void main(String[] args) {<br \/>System.setProperty(&#8220;webdriver.chrome.driver&#8221;, &#8220;Chrome exe path&#8221;);<br \/>WebDriver driver = new ChromeDriver();<br \/>driver.manage().window().maximize();<\/p>\n<p>driver.get(&#8220;https:\/\/www.facebook.com\/&#8221;);<br \/>\/\/Code to find element using id and send values in text field.<br \/>driver.findElement(By.id(&#8220;email&#8221;)).clear();<br \/>driver.findElement(By.id(&#8220;pass&#8221;)).clear();<br \/>\/\/Close chrome driver<br \/>driver.close();<br \/>\u00a0 \u00a0 }<br \/>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1608886922958\"><strong>Buttons<\/strong><\/h3>\n<p>The buttons can be accessed using the click() method.<\/p>\n<p>Let us see an example where we are entering details and clicking on submit button to navigate to next page.<\/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\" data-css=\"tve-u-1769931e8a8\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17699302a4c\" style=\"\">\n<p data-css=\"tve-u-176992ffe50\" style=\"\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p>public class SubmitButton {<\/p>\n<p>public static void main(String[] args) {<br \/>System.setProperty(&#8220;webdriver.chrome.driver&#8221;, &#8220;Chrome exe path&#8221;);<br \/>WebDriver driver = new ChromeDriver();<br \/>driver.manage().window().maximize();<\/p>\n<p>driver.get(&#8220;https:\/\/rahulshettyacademy.com\/AutomationPractice\/&#8221;);<br \/>\/\/Code to find element using id and send values in text field.<br \/>driver.findElement(By.id(&#8220;name&#8221;)).sendKeys(&#8220;Rahul Shetty&#8221;);<br \/>driver.findElement(By.id(&#8220;alertbtn&#8221;)).click();<br \/>\/\/Close chrome driver<br \/>driver.close();<br \/>\u00a0 \u00a0 \u00a0}<br \/>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5 class=\"\" id=\"t-1608886922960\"><strong>Submit buttons<\/strong><\/h5>\n<p>Submit buttons are used to submit the entire form to the server. We can either use the click () method on the web element like a normal button as we have done above or use the submit () method on any web element in the form or on the submit button itself.<\/p>\n<p>When submit() is used, WebDriver will look up the DOM to know which form the element belongs to, and then trigger its submit function.<\/p>\n<p>Let us check example with code for submit button.<\/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\" data-css=\"tve-u-176993251b2\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17699317148\" style=\"\">\n<p style=\"color: rgb(255, 255, 255) !important; --tcb-applied-color:rgb(255, 255, 255)  !important;\">package tests;<\/p>\n<p>import org.openqa.selenium.By;<br \/>import org.openqa.selenium.WebDriver;<br \/>import org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p>public class SubmitButton {<\/p>\n<p>public static void main(String[] args) {<br \/>System.setProperty(&#8220;webdriver.chrome.driver&#8221;, &#8220;Chrome exe path&#8221;);<br \/>WebDriver driver = new ChromeDriver();<br \/>driver.manage().window().maximize();<\/p>\n<p>driver.get(&#8220;https:\/\/rahulshettyacademy.com\/AutomationPractice\/&#8221;);<br \/>\/\/Code to find element using id and send values in text field.<br \/>driver.findElement(By.id(&#8220;name&#8221;)).sendKeys(&#8220;Rahul Shetty&#8221;);<br \/>driver.findElement(By.id(&#8220;alertbtn&#8221;)).submit();<br \/>\/\/Close chrome driver<br \/>driver.close();<br \/>\u00a0 \u00a0 \u00a0}<br \/>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element tve-froala fr-box fr-basic\">\n<h3 class=\"\" id=\"t-1608886922961\"><strong>Complete Code<\/strong><\/h3>\n<p>Let us take one complete code for all the above things we have gone through in this article.<\/p>\n<ul>\n<li>Open <a class=\"tve-froala\" href=\"https:\/\/www.facebook.com\/\" style=\"outline: none;\">https:\/\/www.facebook.com\/<\/a><\/li>\n<li>Enter email address and password.<\/li>\n<li>Press login button.<\/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\" data-css=\"tve-u-1769933a069\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17699331307\" style=\"\">\n<p data-css=\"tve-u-1769933476a\" 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;<\/p>\n<p>public class LoginTestCase {<\/p>\n<p>public static void main(String[] args) {<br \/>System.setProperty(&#8220;webdriver.chrome.driver&#8221;, &#8220;Chrome exe path&#8221;);<br \/>WebDriver driver = new ChromeDriver();<br \/>driver.manage().window().maximize();<\/p>\n<p>driver.get(&#8220;https:\/\/rahulshettyacademy.com\/AutomationPractice\/&#8221;);<br \/>\/\/Code to find element using id and send values in text field.<br \/>WebElement email = driver.findElement(By.id(&#8220;email&#8221;));<br \/>WebElement password = driver.findElement(By.id(&#8220;pass&#8221;));<br \/>WebElement login = driver.findElement(By.id(&#8220;u_0_i&#8221;));<\/p>\n<p>\/\/code to send keys to edit box<br \/>email.sendKeys(&#8220;Rahul Shetty&#8221;);<br \/>password.sendKeys(&#8220;1234567&#8221;);<\/p>\n<p>\/\/code to clear edit box.<br \/>email.clear();<br \/>password.clear();<\/p>\n<p>\/\/code to send keys to edit box and click on login button.<br \/>email.sendKeys(&#8220;rahul shetty&#8221;);<br \/>password.sendKeys(&#8220;0987654321&#8221;);<\/p>\n<p>\/\/code to press login button using submit()<br \/>login.submit();<\/p>\n<p>\/\/Close chrome driver<br \/>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=\"\"><strong>Summary<\/strong><\/h3>\n<ul type=\"disc\">\n<li>The table below summarizes the commands to access each type of element discussed above<\/li>\n<\/ul>\n<table border=\"1\" cellpadding=\"0\">\n<thead>\n<tr>\n<td>\n<p align=\"center\"><strong>Element<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Command<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td rowspan=\"2\">\n<p><strong>Input Box<\/strong><\/p>\n<\/td>\n<td>\n<p>sendKeys()<\/p>\n<\/td>\n<td>\n<p>used to enter values onto text boxes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>clear()<\/p>\n<\/td>\n<td>\n<p>used to clear text boxes of its current value<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><strong>Links<\/strong><\/p>\n<\/td>\n<td>\n<p>click()<\/p>\n<\/td>\n<td>\n<p>used to click on the link and wait for page load to complete before proceeding to the next command.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><strong>Submit Button<\/strong><\/p>\n<\/td>\n<td>\n<p>submit()<\/p>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\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>Table Of Contents 0.1 What are Form WebElement? 0.2 Introduction to WebElement, findElement(), findElements() 0.3 Input Box 0.4 sendKeys in Selenium 0.4.1 Entering values in Input Boxes 0.5 Deleting values in input boxes 0.6 Buttons 0.6.1 Submit buttons 0.7 Complete Code 0.8 Summary What are Form WebElement? Forms are the fundamental web elements to receive [&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-256","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\/256","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=256"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}