Selenium WebDriver – User interaction (II)

Tram Ho

In the previous article, we have learned about the operations with Text Box, Radio Button, Drop Down.

This article we will learn about manipulating objects: check box, drag and drop, and keyboard operations.

I. Interact with checkboxes in Selenium

We can select a checkbox using the ‘click’ method and deselect by the ‘click’ method. Identify XPath using the ChroPath plugin on Chrome browser. This example uses the website http://www.calculator.net/mortgage-calculator.html

Result:

Is Selected: false Is Enabled: true Is Displayed: true Is Selected true

II. Drag and drop in Selenium

We will perform drag and drop in Selenium by selecting a directory tree available on http://www.keenthemes.com/preview/metronic/templates/admin/ui_tree.html . In this example, we will drag an ‘Disable Node’ element from the ‘Initial Open’ folder to the ‘Parent Node’ folder.

Result:

III. Working with keyboards in selenium

We will perform keyboard operations in Selenium using the WebElement.sendKeys () or Actions.sendKeys () methods. Send keys to represent keyboard in browser. Special keys that are not text, are denoted by Keys that are identified as part of a single character string or character. The following is an example of performing a keyboard operation in Selenium to open https://google.com , enter the keyword ‘Son Tung MTP’ and press the Enter key to perform a search.

1. Use the Actions.sendKeys () method:

Result:

2. Using the WebElement.sendKeys () method:

So we have learned how to operate with Checkbox, drag and drop, and use the keyboard in Selenium. In the next article, we will learn about Mouse Actions, select multiple items and find all links in Selenium.

Share the news now

Source : Viblo