Showing posts with label Best Explanation of Selenium Commands. Show all posts
Showing posts with label Best Explanation of Selenium Commands. Show all posts

Saturday, April 18, 2020

Selenium WebDriver - WebElement Commands

Web Element means HTML element available on web page. Web Page is the combination of different elements which include majorly HTML element.

In WebDriver, we have several commonly used web element commands and actions. The following screenshot displays the eclipse web element command panel.


Please learn about how to locate the web element first, because once you know how to locate then you can perform actions on web element.


Refer Tutorial on : How to Locate Web Element?


Now we can start learning on the Web Element Commands:



1> Clear Command: This method will clear down the value from the element.


Syntax: clear();


Example: first_name.clear();





2> Sendkeys Command: This method will send text to textbox.


Syntax: sendKeys(CharSequence? KeysToSend) : void  


Example: first_name.sendKeys("SLT Learning");





3> Click Command: This method will help us to click on button or link on web page.


Syntax: click() : void   


Example: sub_Button.click();





4> isDisplayed Command: This method used to verify presence of a web element within the webpage. 


The method is designed to result from a Boolean value with each success and failure. The method returns a “true” value if the specified web element is present on the web page and a “false” value if the web element is not present on the web page.


Syntax: isDisplayed() : boolean    


Example: boolean dis_status = swim_CheckBox.isDisplayed();


5> isEnabled() Command: This is the method used to verify if the web element is enabled or disabled within the webpage. 


Like isDisplayed() method, it is designed to result in a Boolean value with each success and failure. The method returns a “true” value if the specified web element is enabled on the web page and a “false” value if the web element is not enabled (state of being disabled) on the web page.


Syntax: isEnabled() : boolean    


Example: boolean ena_status = swim_CheckBox.isEnabled(); 


6> isSelected Command: This method method used to verify if the web element is selected or not. 


isSelected() method is pre-dominantly used with radio buttons, dropdowns and checkboxes. Analogous to above methods, it is designed to result a Boolean value with each success and failure.


Syntax: isSelected() : boolean    


Example: boolean sel_status = swim_CheckBox.isSelected();





Key Notes for isDisplayed(), isSelected() and isEnabled():



  • isDisplayed() is the method used to verify a presence of a web element within the webpage. The method returns a “true” value if the specified web element is present on the web page and a “false” value if the web element is not present on the web page.
  • isDisplayed() is capable to check for the presence of all kinds of web elements available.
  • isEnabled() is the method used to verify if the web element is enabled or disabled within the webpage.
  • isEnabled() is primarily used with buttons.
  • isSelected() is the method used to verify if the web element is selected or not.
  • isSelected() method is predominantly used with radio buttons, dropdowns and checkboxes.

7> Submit Command: This method will submit the details to the web page, mostly used for the button.

Syntax: submit() : void    


Example: form_button.submit();




8> GetText Command: This method will be useful to fetch values from the element or attribute of element and return the string.


Syntax: getText() : String     


Example: String facebook = fb_link.getText();






9> GetTagName Command: This method will return the tag name of that particular web element in string. 


Syntax: getTagName() : String      


Example: String tag_Name = linkedin_link.getTagName();




10> Selecting items from dropdown


There are primarily two kinds of drop downs:


Single select dropdown: A drop-down that allows only single value to be selected at a time.

Multi-select dropdown: A drop-down that allows multiple values to be selected at a time.

HTML Code:





Selenium Code:




11> Handling iframes:  IFrame is a web page which is embedded in another web page or an HTML document embedded inside another HTML document.


The IFrame is often used to insert content from another source, such as an advertisement, into a Web page. The <iframe> tag specifies an inline frame.


By Index: driver.switchTo().frame(1);

By Name or Id: driver.switchTo().frame("<FrameName>");
By Web Element: driver.switchTo().frame(parentFrame);

Switch back to parent or default frame:


driver.switchTo().parentFrame();

driver.switchTo().defaultContent();

12> Capture Screenshot: Screenshots are desirable for bug analysis. Selenium can automatically take screenshots during execution.


Step 1) Convert web driver object to TakeScreenshot

Step 2) Call getScreenshotAs method to create image file
Step 3) Copy file to Desired Location



😀 TIME TO IMPLEMENT the Same IN YOUR ECLIPSE NOW 😀

Selenium WebDriver - Navigation Commands

WebDriver provides some basic Browser Navigation Commands that allows the browser to move backwards or forwards in the browser's history.

Managing history of web based application sometime very useful to complete the test case and functionalities.

List of all Navigation Commands in Selenium WebDriver



1> Navigate To Command: This method loads a new web page in the existing browser window. It accepts String as parameter and returns void.

Syntax: to(String arg0) : void  

Example: driver.navigate().to("https://sltlearning.blogspot.com/");




2> Forward Command: This method enables the web browser to click on the forward button in the existing browser window. It neither accepts anything nor returns anything.

Syntax: forword() : void  

Example: driver.navigate().forward();  

3> Back Command: This method enables the web browser to click on the back button in the existing browser window. It neither accepts anything nor returns anything.

Syntax: back() : void   

Example: driver.navigate().back();  

4> Refresh Command: This method refresh/reloads the current web page in the existing browser window. It neither accepts anything nor returns anything.

Syntax: refresh() : void 

Example: driver.navigate().refresh();  

😀 TIME TO IMPLEMENT the Same IN YOUR ECLIPSE NOW 😀



~~~~~ Time to do Practical Now ~~~~~



  1. Invoke Chrome Browser
  2. Navigate to URL: https://sltlearning.blogspot.com/
  3. Click on the "About SLT Learning" link 
  4. Come back to the Home page using the back command
  5. Again go back to the About SLT Learning Page using forward command
  6. Again come back to the Home page using To command
  7. Refresh the Browser using Refresh command
  8. Close the Browser  

Do not Copy, Write Down in Your eClipse for Better Learning  😀





Friday, April 17, 2020

Common Commands in Selenium WebDriver

Commands which are useful to perform the common or we can say frequently use action and operation on web page to complete the test.

Types of common web driver commands: [Click on Each Link to know more]


Quick View of Common Command:


Syntax of Command:




Most Frequently Used Commands in Selenium Script:

1> Direct to web page or Launch Web page on browser

Using GET method





Using Navigate method





Note: Main difference between Get () and Navigate () is, both performing the same task but with the use of Navigate () you can move back () or forward () in your session’s history.

Navigate is faster then Get, because navigate does not wait for the page to load fully.



2> Locating text box and sending user inputs



3> Clearing User Inputs





4> Fetching data over any web element



5> Performing click event



6> Refresh/Reload the web page



7> Switching window




8> Moving between Frames




9> Drag and Drop





😀 TIME TO IMPLEMENT the Same IN YOUR ECLIPSE NOW 😀