{"id":9843,"date":"2021-06-25T20:28:19","date_gmt":"2021-06-25T14:58:19","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=9843"},"modified":"2025-11-19T01:32:33","modified_gmt":"2025-11-19T06:32:33","slug":"list-of-selenium-commands","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/list-of-selenium-commands\/","title":{"rendered":"List of Selenium Commands"},"content":{"rendered":"\n<p><strong>In Selenium, <\/strong>all those\u00a0 commands in which we perform certain operations like open a window, or we get a URL or we clear some text from the view are controlled by some commands these commands are called as <strong><a href=\"https:\/\/www.h2kinfosys.com\/blog\/list-of-selenium-commands\/\" class=\"rank-math-link\">selenium commands<\/a><\/strong>.<\/p>\n\n\n\n<p>There are three types of commands like:<\/p>\n\n\n\n<p><strong>Actions<\/strong>&#8211; These commands directly interacts with the page elements like click, type etc.<\/p>\n\n\n\n<p><strong>Accessors<\/strong>&#8211; Allows to store the values.<\/p>\n\n\n\n<p><strong>Assertions- <\/strong>It asserts (when this commands fails, test stopped), verifies (when this fails, result logs the failure and continues with execution Wait For (waiting period).<\/p>\n\n\n\n<p>Selenium webdriver has a huge list of commands which are used for test automation which is performed by different operations.<\/p>\n\n\n\n<p>They are:<\/p>\n\n\n\n<p><strong>1.Browser commands<\/strong><\/p>\n\n\n\n<p><strong>2.Navigation commands<\/strong><\/p>\n\n\n\n<p><strong>3. Webelements commands<\/strong><\/p>\n\n\n\n<p><strong>1. BROWSER Commands:<\/strong><\/p>\n\n\n\n<p>a) <strong>Get<\/strong> command<\/p>\n\n\n\n<p>This method opens a new webpage in existing browser. It accepts the parameter as string and returns void.<\/p>\n\n\n\n<p><strong>get(String&nbsp;arg0)&nbsp;:&nbsp;<\/strong><strong>void<\/strong><strong>&nbsp;<\/strong><\/p>\n\n\n\n<p>For example the command to load a website will be written as<\/p>\n\n\n\n<p>Driver.get(\u201cwww.google.com\u201d)<\/p>\n\n\n\n<p>Create a class browserFunctions in java and package and write the code to open the google webpage.<\/p>\n\n\n\n<p>b) <strong>GetPageSource<\/strong> command:<\/p>\n\n\n\n<p>Here the method returns the source code of present webpage loaded on the current browser this accepts no parameter and returns string value.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>getPageSource():&nbsp;String&nbsp;&nbsp;<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>driver.getPageSource();&nbsp;&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;or<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String&nbsp;PageSource&nbsp;=&nbsp;driver.getPageSource();&nbsp;&nbsp;<\/strong><\/pre>\n\n\n\n<p>c) <strong>GetCurrentURL <\/strong>command:<\/p>\n\n\n\n<p>The job of this command is to fetch the string which represents the current URL of the current webpage. This command returns a string value.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>getCurrentUrl():&nbsp;String&nbsp;&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>F<\/strong>or example, this command can be written&nbsp; as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>driver.getCurrentUrl();<\/strong><\/pre>\n\n\n\n<p><strong>Or<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String&nbsp;CurrentUrl&nbsp;=&nbsp;driver.getCurrentUrl<\/strong>();<\/pre>\n\n\n\n<p>d) <strong>Get title <\/strong>command:<\/p>\n\n\n\n<p>This command fetches the title of the current webpage. This command accepts no parameter and returns a string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>getTitle():&nbsp;String<\/strong><\/pre>\n\n\n\n<p>For example this command can be written as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>driver.getTitle();&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;OR<\/strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String&nbsp;Title&nbsp;=&nbsp;driver.getTitle();&nbsp;<\/strong><\/pre>\n\n\n\n<p>e)&nbsp;<strong>Close<\/strong> command<\/p>\n\n\n\n<p>The command is used to terminate the current browser window by operating by the webdriver at the current time. This method returns void.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>close():&nbsp;<\/strong><strong>void<\/strong><strong>&nbsp;<\/strong><\/pre>\n\n\n\n<p>f) <strong>Quit<\/strong> command<\/p>\n\n\n\n<p>This method terminates all the windows operating by the web driver. It closes the browser itself. This returns void.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>quit():&nbsp;<\/strong><strong>void<\/strong><strong>&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>F<\/strong>or example this can be written as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>driver.quit();&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>2. NAVIGATION commands:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Navigate To<\/strong><\/li><\/ol>\n\n\n\n<p>This method loads the new page in the current browser window. It returns nothing and accepts a string parameter.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>to(String&nbsp;arg0)&nbsp;:&nbsp;<\/strong><strong>void<\/strong><\/pre>\n\n\n\n<p>for example it can be written as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>driver.navigate().to<\/strong><strong>(\u201cWWW.H2KINFOSYS.COM\u201d)<\/strong><strong>.<\/strong><\/pre>\n\n\n\n<p><strong>b) <\/strong><strong>Navigate Forward<\/strong><\/p>\n\n\n\n<p>This method does the operation of clicking the forward button of any browser.It will not accept any parameter and not returns any value.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>forward()&nbsp;:&nbsp;<\/strong><strong>void<\/strong><strong>&nbsp;<\/strong><\/pre>\n\n\n\n<p>for example it is written as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>driver.navigate().forward();&nbsp;&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>c) Navigate Back command<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;In this web driver this method simulates the browser\u2019s back button action. It will not allow any parameter and it returns void.<\/p>\n\n\n\n<p><strong>Driver. Navigate ().back ();<\/strong><\/p>\n\n\n\n<p>For example&nbsp; &nbsp; <strong>driver.navigate ().back();<\/strong><\/p>\n\n\n\n<p><strong>d) Refresh command<\/strong><\/p>\n\n\n\n<p>This method works as to refresh the browser. It does not take any parameter and returns void.<\/p>\n\n\n\n<p><strong>driver.navigate().refresh();<\/strong><\/p>\n\n\n\n<p>For example&nbsp; <strong>driver.navigate().refresh();<\/strong><strong><\/strong><\/p>\n\n\n\n<p><strong>3) WEB ELEMENTS COMMANDS:<\/strong><\/p>\n\n\n\n<p><strong>a) Clear command<\/strong><\/p>\n\n\n\n<p>This method is used to clear the value of text type element. It will not accept any parameter and returns void.<\/p>\n\n\n\n<p><strong>WebElement user = driver.findElement(By.id(&#8220;User&#8221;));<\/strong><\/p>\n\n\n\n<p><strong>user.clear();<\/strong><\/p>\n\n\n\n<p><strong>b) Sendkeys command<\/strong><\/p>\n\n\n\n<p>This method prints the characters or values passed in the argument into the associated web element object.it will accept a char sequence as a parameter and its return type is void.<\/p>\n\n\n\n<p><strong>element.sendKeys(\u201center text\u201d);<\/strong><\/p>\n\n\n\n<p>for example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>WebElement user = driver.findElement(By.id(\"User\"));<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>user.sendKeys(\u201cTechBeamers\");<\/strong><\/pre>\n\n\n\n<p><strong>c) Click command<\/strong><\/p>\n\n\n\n<p>The method does the click action at the web element; it will not accept any parameter and its return type is void.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>&nbsp;<\/strong><strong>element.click();<\/strong><\/pre>\n\n\n\n<p>for example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>WebElement user = driver.findElement(By.id(\u201cUser\"));<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>booleanis displayed = user.isDisplayed<\/strong>();<\/pre>\n\n\n\n<p><strong>d) GetText command<\/strong><\/p>\n\n\n\n<p>This method will give you the inner text value of the element and get Text () method may return a blank if the text is hidden.<\/p>\n\n\n\n<p><strong>element.getText();<\/strong><\/p>\n\n\n\n<p>for example<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>WebElement link = driver.findElement(By.xpath(\"MyLink\"));<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String strlink = link.getText();<\/strong><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Selenium, all those\u00a0 commands in which we perform certain operations like open a window, or we get a URL or we clear some text from the view are controlled by some commands these commands are called as selenium commands. There are three types of commands like: Actions&#8211; These commands directly interacts with the page [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9846,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-9843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/9843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=9843"}],"version-history":[{"count":1,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/9843\/revisions"}],"predecessor-version":[{"id":32155,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/9843\/revisions\/32155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/9846"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=9843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=9843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=9843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}