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

Selenium Java

The document outlines various operations and functionalities of Selenium WebDriver, including launching a browser, handling windows and tabs, using locators, and performing actions like waits, alerts, and mouse movements. It also covers dropdown and checkbox handling, scrolling, assertions, and element validation. Finally, it explains how to close the browser after operations are completed.

Uploaded by

Siddharth Singh
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 views6 pages

Selenium Java

The document outlines various operations and functionalities of Selenium WebDriver, including launching a browser, handling windows and tabs, using locators, and performing actions like waits, alerts, and mouse movements. It also covers dropdown and checkbox handling, scrolling, assertions, and element validation. Finally, it explains how to close the browser after operations are completed.

Uploaded by

Siddharth Singh
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

🔹 1) Launch Browser + Basic Window

Operations
WebDriver driver = new ChromeDriver();​

[Link]("[Link] // Navigate to URL​

[Link]().window().maximize(); // Maximize​
[Link]().window().minimize(); // Minimize​

[Link]().to("[Link] // Navigate to another URL​
[Link]().back();​
[Link]().forward();​
[Link]().refresh();

🔹 2) Open New Window / Tab


[Link]().newWindow([Link]); // New window​
[Link]("[Link]

// OR new tab​
[Link]().newWindow([Link]);

🔹 3) Locators + Basic Actions


[Link]([Link]("username")).sendKeys("Vedant"); // Send text​
[Link]([Link]("loginBtn")).click(); // Click button
🔹 4) Waits (Very Important)
🔸 Implicit Wait
[Link]().timeouts().implicitlyWait([Link](10));

🔸 Explicit Wait
WebDriverWait wait = new WebDriverWait(driver, [Link](10));​

WebElement element = [Link](​
[Link]([Link]("username"))​
);​
[Link]("Test");

🔹 5) Handling Frames
[Link]().frame("frameName"); // by name/id​
[Link]().frame(0); // by index​

WebElement frame = [Link]([Link]("frameId"));​
[Link]().frame(frame); // by WebElement​

[Link]().defaultContent(); // back to main page

🔹 6) Alerts Handling
Alert alert = [Link]().alert();​

[Link](); // OK​
[Link](); // Cancel​
[Link]("Text"); // Input​
String text = [Link]();
🔹 7) Drag and Drop + Mouse Actions
Actions actions = new Actions(driver);​

WebElement source = [Link]([Link]("drag"));​
WebElement target = [Link]([Link]("drop"));​

[Link](source, target).perform();

🔹 8) Mouse Movement / Hover


WebElement menu = [Link]([Link]("menu"));​

[Link](menu).perform();​
[Link](menu).perform();​
[Link](menu).perform(); // Right click

🔹 9) Dropdown Handling
Select dropdown = new Select([Link]([Link]("dropdown")));​

[Link]("Option1");​
[Link]("value1");​
[Link](1);

🔹 10) Checkbox Handling


WebElement checkbox = [Link]([Link]("check"));​

if (![Link]()) {​
[Link]();​
}

🔹 11) Scrolling
JavascriptExecutor js = (JavascriptExecutor) driver;​

// Scroll down​
[Link]("[Link](0,500)");​

// Scroll up​
[Link]("[Link](0,-500)");​

// Scroll to element​
WebElement element = [Link]([Link]("target"));​
[Link]("arguments[0].scrollIntoView(true);", element);

🔹 12) Assertions (Hard Assertions -


TestNG style)
🔸 Basic Assertions
[Link](actual, expected);​
[Link](actual, expected);​

[Link](condition);​
[Link](condition);​

[Link](object);​
[Link](object);
🔹 13) Soft Assertions
SoftAssert soft = new SoftAssert();​

[Link](actual, expected);​
[Link](condition);​

// Important​
[Link](); // marks test result

🔹 14) Verify (Common Practice in


Selenium)
👉 Selenium doesn’t have built-in verify, we simulate it:
if ([Link](expected)) {​
[Link]("Verified");​
} else {​
[Link]("Failed but test continues");​
}

🔹 15) Element Validation (Verify UI State)


WebElement element = [Link]([Link]("test"));​

[Link]();​
[Link]();​
[Link]();

🔹 16) Close Browser


[Link](); // current window​
[Link](); // all windows

You might also like