0% found this document useful (0 votes)
4 views13 pages

Selenium Adv Code

The document contains multiple Java classes using Selenium WebDriver to automate browser interactions. It demonstrates handling multiple windows and tabs, navigating to specific URLs, and verifying text on web pages. Additionally, it includes examples of using XPath operators to extract text based on conditions from HTML elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Selenium Adv Code

The document contains multiple Java classes using Selenium WebDriver to automate browser interactions. It demonstrates handling multiple windows and tabs, navigating to specific URLs, and verifying text on web pages. Additionally, it includes examples of using XPath operators to extract text based on conditions from HTML elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

By;

import [Link];

import [Link];

import [Link];

import [Link];

public class MultipleWindowsTest {

public static void main(String[] args) {

[Link]("[Link]", "PATH_TO_CHROMEDRIVER");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

// Get the parent window handle

String parentWindowHandle = [Link]();

// Click on the "Open New Window" button

WebElement newWindowBtn = [Link]([Link]("newWindow"));

[Link]();

// get all window handles

Set<String> windowHandlesSet = [Link]();

for(String windowHandle : windowHandlesSet) {

if(!([Link](parentWindowHandle))) {

// switching to new window


[Link]().window(windowHandle);

String title = [Link]();

[Link](title);

[Link]();

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MultipleWindowsTest {

public static void main(String[] args) {

[Link]("[Link]", "PATH_TO_CHROMEDRIVER");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

// Get the parent window handle

String parentWindowHandle = [Link]();


// Click on the "Open New Tab" button

WebElement newWindowBtn = [Link]([Link]("newTab"));

[Link]();

// Get all window handles

Set<String> windowHandlesSet = [Link]();

for(String windowHandle : windowHandlesSet) {

if(!([Link](parentWindowHandle))) {

// switching to new tab

[Link]().window(windowHandle);

String title = [Link]();

[Link](title);

[Link]();

import [Link];

import [Link];

import [Link];

import [Link];
import [Link];

public class MultipleWindowsTest {

public static void main(String[] args) {

[Link]("[Link]", "PATH_TO_CHROMEDRIVER");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

// Get the parent window handle

String parentWindowHandle = [Link]();

// Click on the "Open New Tab" button

WebElement newWindowBtn = [Link]([Link]("newWindow"));

[Link]();

// get all window handles

Set<String> windowHandlesSet = [Link]();

for(String windowHandle : windowHandlesSet) {

if(!([Link](parentWindowHandle))) {

// switching to new window

[Link]().window(windowHandle);

String title = [Link]();

[Link](title);
[Link]();

// get all window handles

windowHandlesSet = [Link]();

[Link](windowHandlesSet);

[Link]();

[Link]().frame(IFRAME_NAME or IFRAME_ID) // [Link]

import [Link];

import [Link];

public class NxtAppsTest {

public static void main(String args[]) {

try {

// Set the path to the ChromeDriver executable

[Link]("[Link]", "PATH_TO_CHROMEDRIVER");
// Launch the Chrome browser

WebDriver driver = new ChromeDriver();

// Navigate to the NxtApps Application

[Link]("[Link]

}catch (Exception e){

[Link]([Link]());

import [Link];

import [Link];

import [Link];

import [Link];

public class NxtAppsTest {

public static void main(String args[]) {

try {

// Set the path to the ChromeDriver executable

[Link]("[Link]", "PATH_TO_CHROMEDRIVER");

// Launch the Chrome browser

WebDriver driver = new ChromeDriver();


// Navigate to the NxtApps Application

[Link]("[Link]

WebElement headingEle = [Link]([Link]("app-heading"));

String expectedHeading = "My Applications";

String actualHeading = [Link]();

if([Link](actualHeading)){

[Link]("Acutal Heading Matched with the Expected Heading");

else {

[Link]("Acutal Heading is not Matched with the Expected Heading");

}catch (Exception e){

[Link]([Link]());

import [Link];

import [Link];

import [Link];

import [Link];

public class NxtAppsTest {

public static void main(String args[]) {

try {
// Set the path to the ChromeDriver executable

[Link]("[Link]", "PATH_TO_CHROMEDRIVER");

// Launch the Chrome browser

WebDriver driver = new ChromeDriver();

// Navigate to the NxtApps Application

[Link]("[Link]

WebElement headingEle = [Link]([Link]("app-heading"));

String expectedHeading = "My Applications";

String actualHeading = [Link]();

if([Link](actualHeading)){

[Link]("Acutal Heading Matched with the Expected Heading");

else {

[Link]("Acutal Heading is not Matched with the Expected Heading");

WebElement blogHubEle = [Link]([Link]("[Link] > :nth-child(2)"));

[Link]();

[Link]().frame("appFrameCard");

WebElement usernameEle = [Link]([Link]("user-name"));

[Link]([Link]());
WebElement aboutLink = [Link]([Link]("About"));

[Link]();

[Link]().frame("appFrameCard");

WebElement aboutPageHeadingEle = [Link]([Link]("about-me-section-


heading"));

expectedHeading = "About me";

actualHeading = [Link]();

if([Link](actualHeading)){

[Link]("Acutal Heading Matched with the Expected Heading -- " +


actualHeading);

else {

[Link]("Acutal Heading is not Matched with the Expected Heading -- "+


actualHeading);

//Switch to Parent iframe

[Link]().parentFrame();

// Access Home Page link

WebElement homeLink = [Link]([Link]("Home"));

[Link]();

usernameEle = [Link]([Link]("user-name"));

[Link]([Link]());
}catch (Exception e){

[Link]([Link]());

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>XPath Operators Example</title>

</head>

<body>

<div class="main">

<p class="intro" data-number="5">This is an intro paragraph.</p>

<p data-number="10">This is a paragraph with a number 10.</p>

</div>

<div class="footer">

<span class="note" hidden>Note: This is a hidden note.</span>

</div>

</body>

</html>
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>XPath Operators Example</title>

</head>

<body>

<div class="main">

<p class="intro" data-number="5">This is an intro paragraph.</p>

<p data-number="10">This is a paragraph with a number 10.</p>

</div>

<div class="footer">

<span class="note" hidden>Note: This is a hidden note.</span>

</div>

</body>

</html>

import [Link];

import [Link];

import [Link];

public class ComparisonOperatorsExample {

public static void main(String[] args) {

// Set the path for chromedriver if needed

[Link]("[Link]", "path_to_chromedriver");
WebDriver driver = new ChromeDriver();

// Navigate to a website

[Link]("[Link]

// Equals To Operator

String equalsToText = [Link]([Link]("//p[@data-number='5']")).getText();

[Link]("Equals To Operator: " + equalsToText);

// Not Equals To Operator

String notEqualsToText = [Link]([Link]("//p[@data-number!='5']")).getText();

[Link]("Not Equals To Operator: " + notEqualsToText);

// Less Than Operator

String lessThanText = [Link]([Link]("//p[@data-number<'10']")).getText();

[Link]("Less Than Operator: " + lessThanText);

// Greater Than Operator

String greaterThanText = [Link]([Link]("//p[@data-number>'5']")).getText();

[Link]("Greater Than Operator: " + greaterThanText);

// Less Than or Equals To Operator

String lessThanOrEqualsToText = [Link]([Link]("//p[@data-


number<='5']")).getText();

[Link]("Less Than or Equals To Operator: " + lessThanOrEqualsToText);

// Greater Than or Equals To Operator


String greaterThanOrEqualsToText = [Link]([Link]("//p[@data-
number>='10']")).getText();

[Link]("Greater Than or Equals To Operator: " + greaterThanOrEqualsToText);

// Close the browser after task completion

[Link]();

You might also like