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

Manipulating The Elements: Test Automation Basics With Selenium & Java

The document provides an overview of test automation basics using Selenium and Java, focusing on WebElement methods such as click(), sendKeys(), getText(), and getAttribute(). It includes practical scenarios demonstrating how to interact with web elements on Google, such as performing a search using both a search button and the Enter key. Additionally, it outlines steps for automating a Google search and printing results and execution time in the console.

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)
2 views9 pages

Manipulating The Elements: Test Automation Basics With Selenium & Java

The document provides an overview of test automation basics using Selenium and Java, focusing on WebElement methods such as click(), sendKeys(), getText(), and getAttribute(). It includes practical scenarios demonstrating how to interact with web elements on Google, such as performing a search using both a search button and the Enter key. Additionally, it outlines steps for automating a Google search and printing results and execution time in the console.

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

Manipulating the elements

Test automation basics with Selenium & Java


By:
Evgeny Novikov
Email:
xevgnov@[Link]
What Selenium can do with WebElement?
WebElement methods:
● click()
● sendKeys(“some string”) or sendKeys([Link])
● getText()
● getAttribute("value")

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Click and
sendKeys
Scenario with search button
WebDriver driver = new ChromeDriver();

[Link]().to( "[Link]

WebElement searchField = [Link](By. id("lst-ib"));

//put ‘selenium java’ text to text field

[Link]( "selenium java");

WebElement searchButton = [Link](By. name("btnK"));

//press on search button

[Link](); By:
Evgeny Novikov
[Link](); Email:
xevgnov@[Link]
Scenario with Enter button
WebDriver driver = new ChromeDriver();

[Link]().to( "[Link]

[Link]([Link]());

WebElement searchField = [Link](By. id("lst-ib"));

//put ‘selenium java’ text to text field

[Link]( "selenium java");

//press ENTER

[Link](Keys. RETURN); By:


Evgeny Novikov
[Link](); Email:
xevgnov@[Link]
getText and
getAttribute
By:
Evgeny Novikov
Email:
xevgnov@[Link]
WebElement methods
<input name="sampleName" value="qwerty">Hello
world!</input>

driver.findElement([Link]("sampleName"))
.getAttribute("value");

driver.findElement([Link]("sampleName"))
.getText(); By:
Evgeny Novikov
Email:
xevgnov@[Link]
getText and getAttribute example
WebDriver driver = new ChromeDriver();

[Link]().to( "[Link]

WebElement gmailLink =
[Link](By. xpath("//a[@class='gb_d']"));

System. [Link]("href attribute contains value: " +


[Link]( "href"));

System. [Link]("element contains text: " +


[Link]());

[Link]();
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Automate steps

1) Open [Link]
2) Find search input field
3) Clear input field
Exercise 4) Put some text to the field
5) Press Enter / Return button
Search with Enter button 6) Print in console number of
results of google search
7) Print in console how many time
took the search
By:
Evgeny Novikov
Email:
xevgnov@[Link]

You might also like