Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

Scritps for Selenium Webdriver

Rating
-
Sold
-
Pages
62
Uploaded on
05-10-2024
Written in
2024/2025

Selenium Web Driver allows you to choose a programming language to create test scripts.

Institution
Course

Content preview

SELENIUM WEBDRIVER SCRIPTS




WWW.PAVANTESTINGTOOLS.COM | WWW.PAVANONLINETRAININGS.COM

,01. WebDriver Basic Commands - Example
package Examples;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class click {

@Test

public void clickmethod()
{
//1. Open the Chrome Browser
System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\chr
omedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

//2. Using Implicitly Wait Command
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//Open the URL
driver.get("http://www.google.com");

//Get and store page title in to variable
String title = driver.getTitle();
System.out.print(title);

//Get current page URL
String CurrentURL = driver.getCurrentUrl();
System.out.println("My Current URL Is : "+CurrentURL);

//Get and store domain name in variable using JavaScript Executor

, JavascriptExecutor javascript = (JavascriptExecutor) driver;
String DomainUsingJS=(String)javascript.executeScript("return
document.domain");
System.out.println("My Current URL Is : "+DomainUsingJS);

// Checked for search box is enabled or not
if (driver.findElement(By.xpath("//input[@name='q']")).isEnabled())
{
System.out.println("Google search text box Is enabled.");

// Pass the Test - "WebDriver Test Successful" to search box
driver.findElement(By.xpath("//input[@name='q']")).sendKey
s("WebDriver Test successful.");

// clicking the search button
driver.findElement(By.xpath("//button[@name='btnG']")).clic
k();

driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);

// Click the Top most link and open to New Tab
WebElement link=driver.findElement(By.xpath("//div[@id='ir
es']/ol/div/div[1]/div/h3/a"));
Actions newTab = new Actions(driver);
newTab.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).click(
link).keyUp(Keys.CONTROL).keyUp(Keys.SHIFT).build().perform();

driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);

}
}

}


02. Navigating Back And Forward

, package Others;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class testsample
{

@Test
public void Navigate_forward_back() throws InterruptedException
{

//1. Open the Chrome Browser
System.setProperty("webdriver.chrome.driver",
"D:\\Softwares\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

//Open the URL
driver.get("http://www.google.com");

//navigate on specific software web application page or URL
driver.navigate().to("http://selenium-venkat.blogspot.com/p/index_4.html");

//To navigate back (Same as clicking on browser back button)
driver.navigate().back();

//To navigate forward (Same as clicking on browser forward button)
driver.navigate().forward();
}
}


03. Capture Screenshot
Capturing screenshot of software web application page is very easy in selenium webdriver.


As we knows, It is very basic required thing in software automation tools to capture screenshot
on test case failure or whenever required during test case execution.


In Selenium WebDriver/Selenium 2, we need to capture screenshot of web page using bellow
syntax.

Written for

Course

Document information

Uploaded on
October 5, 2024
Number of pages
62
Written in
2024/2025
Type
OTHER
Person
Unknown

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
gowrisankar07773

Also available in package deal

Get to know the seller

Seller avatar
gowrisankar07773 Self
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
4
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions