Use this slide if there is no Heading
Note - Create Content inside Red Layout
[Delete Red Outline After creating slide]
Learning Outcome
5
Handle file uploads and complex UI interactions effectively
4
Learn how to manage multiple browser windows or tabs
3
Understand how to switch between frames and nested frames
2
Learn how to handle alerts in web applications
1
Understand the concept of context switching in automation
Topic Name-Recall(Slide3)
Hook/Story/Analogy(Slide 4)
Transition from Analogy to Technical Concept(Slide 5)
Working with Alerts: Accept, Dismiss, Read
Common Alert Methods
When To Use
driver.switchTo().alert().getText();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().accept();
Confirmation dialogs
Warning messages
Input prompts
Scenario: Deleting a Record with Confirmation Alert
Handle Alert
Read the alert text and accept the confirmation.
Click Delete Button
Find the delete icon and trigger the action.
Verify Deletion
Confirm the record has been removed from the list.
Frames: Independent Web Pages Inside a Page
An HTML element that embeds another HTML document within the current page
Selenium cannot access elements inside frames without explicitly switching context
Embedded forms, media players, maps, and third-party content
What Is an iFrame?
The Challenge
Common Uses
3Ways to Switch to a Frame
ByWebElement
driver.switchTo().frame(frameElement);
​Return to Main Page
driver.switchTo().defaultContent();
By Name or ID
driver.switchTo().frame("frameId");
By Index
driver.switchTo().frame(0);
Frames: Independent Web Pages Inside a Page
Switch to Outer Frame driver.switchTo().frame("outerFrame");
Switch to Inner Frame driver.switchTo().frame("innerFrame");
Interact with Form driver.findElement(By.id("email")).sendKeys("test@example.com ")
Return to Main Page driver.switchTo().defaultContent();
Switching BetweenWindows Like a Pro
All Open Windows
Set allWindows = driver.getWindowHand les();
Switch Windows
driver.switchTo().windo w(windowId);
Return to Original
driver.switchTo().windo w(mainWindow);
Current Window
String mainWindow = driver.getWindowHand le();
Scenario: Handling File Uploads via Windows
The Challenge OS
file dialogs cannot be controlled by Selenium directly
The Solution
Use sendKeys() to set the file path on file input elements
Implementation
WebElement upload =driver.findElement(By.id("uploadFile")); upload.sendKeys("C:\\Users\\file.txt");
Switch Smartly: KnowYour Context
Context Type
Switch Method
Reset Method
Auto-reset after action
Alerts
switchTo().alert()
Frames
switchTo().frame()
switchTo().defaultC ontent()
switchTo().window( originalHandle)
switchTo().window( )
Windows
Summary
5
After interaction, it is important to return to the original context
4
Multiple browser windows require switching using window handles
3
Frames are small sections in a page, so you must switch to use them
2
Alerts require switching to the alert before accepting or dismissing it
1
Selenium sometimes needs to switch context to interact with certain elements
Quiz
Which method returns to the main page after switching to a frame?
A. switchTo().main()
B. switchTo().defaultContent()
C. switchTo().parentPage()
D. switchTo().home()
Quiz-Answer
Which method returns to the main page after switching to a frame?
A. switchTo().main()
B. switchTo().defaultContent()
C. switchTo().parentPage()
D. switchTo().home()
Please create an account to use this template.