MORE ON SELENIUM WEBDRIVER

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.

1

  • The output will be something like this.

First it will open the browser and redirect to the URL.

2.png

Then it will select the radio button.

3

5

After the browser closed down we can check the output terminal.

6.png

  • Now let’s see how to work with drop down menus.

7.png

  • First it will open the browser window.

8.png

Then will select the choice from the drop down.

9

10

  • 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

11.png

  • Let’s see the output.

First the browser window.

12

Then it will select items.

13

14

The output terminal.

15

  • 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.

16.png

  • Now let’s look at the output.

First it will open the browser window.

17

After it closed, let’s checkout the out put terminal. It will list all the links in that page.

18

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.

Keyboard actions,

  • 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().

Mouse actions,

  • click() – left click.
  • contextClick() – right click.
  • doubleClick()
  • mouseDown()
  • mouseMove()
  • mouseUp()

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!

Advertisements

One thought on “MORE ON SELENIUM WEBDRIVER

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s