Hi all, from a previous post we talked about Selenium WebDriver and we paused it there for another post. From this post I’m going to talk about the rest of the commands. Previously we saw how to work with the text boxes. Now let’s see how to work with check boxes and the radio buttons. It’s same for the both check boxes and the radio buttons.
- First of all I think you have the previous JAVA code. Then add this code to it.
isSelected() will check whether the specific radio button or check box is checked or not.
click() will select and deselected the radio button.
isDisplayed() and isEnabled() will check whether the element is displayed or not and enabled or disabled respectively.
- The output will be something like this.
First it will open the browser and redirect to the URL.
Then it will select the radio button.
After the browser closed down we can check the output terminal.
- Now let’s see how to work with drop down menus.
- First it will open the browser window.
Then will select the choice from the drop down.
- Now will check how to do multiple selections using WebDriver.
click() method will use to click on specific elements.
findElements() will return a list of matching elements.
size() will return the size of the list.
options.get() will select specific items by index.
perform() will do the selections
- Let’s see the output.
First the browser window.
Then it will select items.
The output terminal.
- Let’s see how to find all the links in a specific page. Here we can identify elements by the HTML tag.
tagName() will select the element by it’s html tag.
size() will return the size of the result.
Then using the for loop we can iterate among the resulted list.
get() will select the specific link from it’s index.
getText() will return the text value of the link.
- Now let’s look at the output.
First it will open the browser window.
After it closed, let’s checkout the out put terminal. It will list all the links in that page.
Those are the few basic commands relevant to some elements in WebDriver. Here we have talked about how to identify an element. Those command are known as ‘Locators‘. Let’s see all the locators,
- findElement() – This will find one matching element.
- findElements() – This will find all the matching elements.
- By.id() – Identify an element using it’s ID.
- By.name() – Identify an element using it’s name.
- By.className() – Identify an element using it’s class name.
- By.tagName() – Identify an element using it’s html tag.
- By.linkText() – Identify a link using it’s link text.
- By.partialLinkText() – Identify a link using it’s partial link text.
- By.cssSelector() – Identify an element using it’s css selector.
- By.xpath() – Identify an element using it’s xpath. We can find the xpath using the FurePath extension for FireFox.
Also there are few keyboard and mouse actions like clicking() what we talked earlier.
- sendKeys() – type text in a browser.
- pressKey() – press a key. Not a text key, like a functional key.
- releaseKey() – release the key after pressed. Most suitable for the functional keys after calling the pressKey().
- click() – left click.
- contextClick() – right click.
Those are the few basic comands used in WebDriver and all the locators used to identify an element. Hope now you have a clear idea about the Selenium WebDriver. See you soon with another interesting topic. Thank You!