Selenium with Javascript – Accessing different Elements
We had discussed about Locators in our last session, So we know that we can use Locators to access or locate different type of Elements. Now, we get a question, that how many types of Elements, do we have in a Web Application, and the answer is, there can be many type of Elements. At the same time, We have to know, that what action has to be performed on which element. Elements are called Web Elements because these elements belong to a Web Application.
Type of Web Elements
We have different type of Web Elements in a Web Application.
- Text Area
- Button
- Checkbox
- Radio Button
- Input Field
- Dropdown
- Image
Actions associated to Web Elements
- Text Area – Enter Text
- Button – Click on the Button
- Checkbox – Click on the Checkbox
- Radio Button – Click on the Radio Button
- Input Field – Enter Text
- Dropdown – Select a value from the Dropdown
- Image – Click on the Image
Method in Selenium for each Action
- Enter Text in a Text area and input field – sendKeys(“”);
- Click on a button, checkbox, radiobutton – click();
- Select Value from dropdown –
- click();
- selectByVisibleText();
- selectByValue();
- selectByIndex();
Example for Accessing Element
Let’s see the example for accessing different types of Elements in a Web Application.
- Navigate to the eCommerce Website.
- Click on any of the Item.
- Click on Add to Basket Button
- Click on View Basket Button
- Click on Proceed to checkout Button
- Enter Shipping and Billing details and click on place Order.
Now, Let’s write Automation script for the same, so that we will get to know, How to access different elements in a Website. We will see this practically in next session one by one.
- First, we will see click examples. We will find the elements where we can click and then we will click on them using click method of Selenium with Javascript.
- Second, we will see sendKeys examples, we will find the elements where we can enter some value and then we will enter some value in the fiels using sendKeys method of Selenium with Javascript.
- Third, we will see dropdown examples, we will find the elements where we have to select some value from dropdown, and try to select value from dropdown using selectByVisibleText method or any other method of Selenium with Javascript.
So, this is how we are going to see, How to access any element in a Web Application using Selenium with Javascript.
Summary
We have covered below topics in this session
- Selenium with Javascript – Accessing different Elements
- Type of Web Elements
- Actions associated to Web Elements
- Method in Selenium for each Action
- Example for Accessing Element