Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SeleniumTraining
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Qazi Zain
SeleniumTraining
Commits
47f73009
Commit
47f73009
authored
Nov 11, 2024
by
Qazi Zain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assigment question is added in ChildWindowHandling Package
parent
b46d1fa8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
AssigmentExample.java
...java/Techniques/ChildWindowHandling/AssigmentExample.java
+61
-0
No files found.
src/test/java/Techniques/ChildWindowHandling/AssigmentExample.java
0 → 100644
View file @
47f73009
package
Techniques
.
ChildWindowHandling
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
java.time.Duration
;
import
java.util.HashSet
;
import
java.util.Iterator
;
public
class
AssigmentExample
{
public
static
void
main
(
String
[]
args
)
{
WebDriver
obj
=
new
FirefoxDriver
();
obj
.
get
(
"https://the-internet.herokuapp.com/"
);
// creating web element of that li locator.
WebElement
text
=
obj
.
findElement
(
By
.
cssSelector
(
"a[href='/windows']"
));
// click on that link
text
.
click
();
// clicking to move on new page:
WebElement
text2
=
obj
.
findElement
(
By
.
cssSelector
(
"div a[href='/windows/new']"
));
text2
.
click
();
HashSet
windows
=
new
HashSet
<>(
obj
.
getWindowHandles
());
Iterator
<
String
>
it
=
windows
.
iterator
();
String
parentWindow
=
it
.
next
();
String
childWindow
=
it
.
next
();
WebDriverWait
wait
=
new
WebDriverWait
(
obj
,
Duration
.
ofSeconds
(
8
));
obj
.
switchTo
().
window
(
childWindow
);
wait
.
until
(
ExpectedConditions
.
visibilityOfElementLocated
(
By
.
cssSelector
(
"div[class='example'] h3"
)));
String
dummyText2
=
obj
.
findElement
(
By
.
cssSelector
(
"div[class='example'] h3"
)).
getText
();
System
.
out
.
println
(
dummyText2
);
obj
.
switchTo
().
window
(
parentWindow
);
wait
.
until
(
ExpectedConditions
.
visibilityOfElementLocated
(
By
.
cssSelector
(
"div[id='content'] div h3"
)));
String
dummyText
=
obj
.
findElement
(
By
.
cssSelector
(
"div[id='content'] div h3"
)).
getText
();
System
.
out
.
println
(
dummyText
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment