0% found this document useful (0 votes)
3 views9 pages

Advanced Actions & Other Selenium Functions: Test Automation Basics With Selenium & Java

The document provides an overview of advanced actions and functions available in Selenium for test automation using Java. It covers simple and advanced actions with web elements, JavaScript execution, and handling windows, alerts, and frames. Additionally, it includes examples and exercises for implementing these actions in test scenarios.

Uploaded by

sxoterry
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Advanced Actions & Other Selenium Functions: Test Automation Basics With Selenium & Java

The document provides an overview of advanced actions and functions available in Selenium for test automation using Java. It covers simple and advanced actions with web elements, JavaScript execution, and handling windows, alerts, and frames. Additionally, it includes examples and exercises for implementing these actions in test scenarios.

Uploaded by

sxoterry
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Advanced actions & other

Selenium functions
Test automation basics with Selenium & Java
By:
Evgeny Novikov
Email:
xevgnov@[Link]
What you can do with Selenium?
● Interact with web elements:
- simple actions
click, sendKeys, getText, getAttribute
- advanced actions
drag and drop, move on element, etc
● Execute javascripts
● Handle windows
● Handle alerts By:
Evgeny Novikov
● Handle frames Email:
xevgnov@[Link]
Actions with WebElements
Simple actions: Advanced actions
click() click()
sendKeys() clickAndHold()
getText() release()
getAttribute() sendKeys()
moveToElement()
doubleClick()
dragAndDrop() By:
Evgeny Novikov
Email:
contextClick() xevgnov@[Link]
How to perform ‘advanced’ action?
class Actions: [Link]

Example1: move cursor to element and execute double click


Actions builder = new Actions(driver);
[Link](element).doubleClick().build().perform();

Example2: Move cursor to element (i.e. to see tip text)


Actions builder = new Actions(driver);
[Link](googleLable).build().perform();
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Simulating CTRL+V action
public void pasteTextToElementFromClipboard(WebElement element,
String text) {
//copy text to memory buffer
Toolkit toolkit = Toolkit. getDefaultToolkit();
Clipboard clipboard = [Link]();
StringSelection strSelection = new StringSelection(text);
[Link]( strSelection , null);
//paste it to the field
[Link](Keys. CONTROL, "v");
}

By:
Evgeny Novikov
Email:
xevgnov@[Link]
JavaScript actions
● Selenium can execute javaScript scenarios.
● Most frequently used action is javaScript click

By:
Evgeny Novikov
Email:
xevgnov@[Link]
JavaScript actions: examples
1) Click on element:
WebElement element = [Link](By. id("test"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
[Link]( "arguments[0].click();", element);

2) SendKeys with javascript:


WebElement field = [Link](By. id("test"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
[Link]( "arguments[0].value = '" + text + "'",
field); By:
Evgeny Novikov
Email:
xevgnov@[Link]
Switch to...
1) Frame
[Link]().frame("frameName");

2) Alert
Alert alert = [Link]().alert();

[Link]();

3) Window
for (String handle : [Link]()) {
By:
Evgeny Novikov
[Link]().window(handle); Email:
xevgnov@[Link]
}
Create test with following steps:
1) Open [Link]
2) Click to search field with Actions
3) Insert text to search field with
javascript
4) click to enter button with actions
Exercise click
5) get results page content using
javascript and check if it contains
Rewrite existing test: replace
text used for search
click() and sendKeys() with
appropriate actions from Action
class
By:
Evgeny Novikov
Email:
xevgnov@[Link]

You might also like