SlideShare a Scribd company logo
Selenium Web Driver Code to handle the following events
How to handle Frames, iFrames:
Frames Code:
driver.switchTo().frame("id"); (Where id was the frame id)
iFrame Code:
WebElement iFrame= driver.findElement(By.(“id”)); (Where id was the
iframe id)
driver.switchTo().frame(iFrame);
How to handle Multiple windows:
Multiple windows Code:
for(String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
driver.manage().window().maximize();
Code for the operations held in new window
String winHandleBefore = "Page Title for parent window";
driver.switchTo().window(winHandleBefore);
How to handle Alerts:
Alert Accept Code:
Alert al=d.switchTo().alert();
String s=al.getText();
assertEquals("Expected value in the alert",s);
al.accept();
Alert Accept Code: For confirmation alerts with ok and cancel buttons
For Alert with click ‘ok’ was same as above
For Alert with click ‘Cancel’ button below was the code:
Alert al=d.switchTo().alert();
String s=al.getText();
assertEquals("Expected value in the alert",s);
al.dismiss();
Insert values in alerts:
Alert al=d.switchTo().alert();
String s=al.getText();
assertEquals("Expected value in the alert",s);
al.sendKeys(“Text”);
al.accept();
How to handle Drag & Drop:
WebElement draggable = driver.findElement(By.id("id"));
WebElement droppable = driver.findElement(By.id("id"));
new Actions(driver).dragAndDrop(draggable, droppable).build().perform();
How to handle Mouse over events:
Actions builder = new Actions(d);
WebElement tagElement = d.findElement(By.id("id"));
builder.moveToElement(tagElement).build().perform();
tagElement.click();
Screenshots on Failure:
try
{
Code
}
catch(Exception e){
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String k="C:eclipseScreenshotsMagError.png";
FileUtils.copyFile(scrFile, new File(k));
}

More Related Content

Viewers also liked

PANDUAN LIBERTY RESERVE -INDONESIA
PANDUAN LIBERTY RESERVE -INDONESIAPANDUAN LIBERTY RESERVE -INDONESIA
PANDUAN LIBERTY RESERVE -INDONESIAsinglee51
 
автомобиль и ос
автомобиль и осавтомобиль и ос
автомобиль и ос
Demanessa
 
Dvg presentation CG Learning
Dvg presentation CG LearningDvg presentation CG Learning
Dvg presentation CG Learning
gjhufken
 
Reality slide
Reality slideReality slide
Reality slide
Cecilie Burleson
 
Robna kuca
Robna kucaRobna kuca
Robna kuca
Dejan Stanojevic
 
Odigos apasxolisis
Odigos apasxolisisOdigos apasxolisis
Odigos apasxolisis
Konstantinos Kotsidis
 
How+to+create+a+power point
How+to+create+a+power pointHow+to+create+a+power point
How+to+create+a+power point
Fiestie
 
методичка по курсовой по 02.01
методичка по курсовой по 02.01методичка по курсовой по 02.01
методичка по курсовой по 02.01
Demanessa
 
LogiExcel - Complete Logistics Solution
LogiExcel -  Complete Logistics SolutionLogiExcel -  Complete Logistics Solution
LogiExcel - Complete Logistics Solution
LogiExcel Logistics Solution
 
Cloud pau papell-activitat2
Cloud pau papell-activitat2Cloud pau papell-activitat2
Cloud pau papell-activitat2ppapell
 
Người giỏi không phải người làm tất cả Ebook - Donna M.Genett
Người giỏi không phải người làm tất cả Ebook - Donna M.GenettNgười giỏi không phải người làm tất cả Ebook - Donna M.Genett
Người giỏi không phải người làm tất cả Ebook - Donna M.Genett
Duyệt Đoàn
 
Humanities Putrajaya worksheet
Humanities Putrajaya worksheetHumanities Putrajaya worksheet
Humanities Putrajaya worksheet
Kirsty Tay
 
Details
DetailsDetails
Ukr part iii ppt (5 july 2016 uspc)
Ukr part iii ppt (5 july 2016 uspc)Ukr part iii ppt (5 july 2016 uspc)
Ukr part iii ppt (5 july 2016 uspc)
Olena Ursu
 

Viewers also liked (16)

PANDUAN LIBERTY RESERVE -INDONESIA
PANDUAN LIBERTY RESERVE -INDONESIAPANDUAN LIBERTY RESERVE -INDONESIA
PANDUAN LIBERTY RESERVE -INDONESIA
 
Android+Education
Android+EducationAndroid+Education
Android+Education
 
автомобиль и ос
автомобиль и осавтомобиль и ос
автомобиль и ос
 
Dvg presentation CG Learning
Dvg presentation CG LearningDvg presentation CG Learning
Dvg presentation CG Learning
 
Reality slide
Reality slideReality slide
Reality slide
 
Robna kuca
Robna kucaRobna kuca
Robna kuca
 
Odigos apasxolisis
Odigos apasxolisisOdigos apasxolisis
Odigos apasxolisis
 
How+to+create+a+power point
How+to+create+a+power pointHow+to+create+a+power point
How+to+create+a+power point
 
методичка по курсовой по 02.01
методичка по курсовой по 02.01методичка по курсовой по 02.01
методичка по курсовой по 02.01
 
LogiExcel - Complete Logistics Solution
LogiExcel -  Complete Logistics SolutionLogiExcel -  Complete Logistics Solution
LogiExcel - Complete Logistics Solution
 
Cloud pau papell-activitat2
Cloud pau papell-activitat2Cloud pau papell-activitat2
Cloud pau papell-activitat2
 
Olena ursu
Olena ursuOlena ursu
Olena ursu
 
Người giỏi không phải người làm tất cả Ebook - Donna M.Genett
Người giỏi không phải người làm tất cả Ebook - Donna M.GenettNgười giỏi không phải người làm tất cả Ebook - Donna M.Genett
Người giỏi không phải người làm tất cả Ebook - Donna M.Genett
 
Humanities Putrajaya worksheet
Humanities Putrajaya worksheetHumanities Putrajaya worksheet
Humanities Putrajaya worksheet
 
Details
DetailsDetails
Details
 
Ukr part iii ppt (5 july 2016 uspc)
Ukr part iii ppt (5 july 2016 uspc)Ukr part iii ppt (5 july 2016 uspc)
Ukr part iii ppt (5 july 2016 uspc)
 

Similar to Selenium web driver code to handle the following events

What the FUF?
What the FUF?What the FUF?
What the FUF?
An Doan
 
Handling iFrames in Selenium Based Test Automation.pdf
Handling iFrames in Selenium Based Test Automation.pdfHandling iFrames in Selenium Based Test Automation.pdf
Handling iFrames in Selenium Based Test Automation.pdf
pCloudy
 
Tutorial 8 menu
Tutorial 8   menuTutorial 8   menu
Tutorial 8 menu
Erlang Herlambang
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Web driver training
Web driver trainingWeb driver training
Web driver training
Dipesh Bhatewara
 
Window object methods (timer related)
Window object methods (timer related)Window object methods (timer related)
Window object methods (timer related)
Shivani Thakur Daxini
 
HTML5 Web Messaging
HTML5 Web MessagingHTML5 Web Messaging
HTML5 Web Messaging
Mike Taylor
 
Talk about html5 security
Talk about html5 securityTalk about html5 security
Talk about html5 security
Huang Toby
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.js
Seth McLaughlin
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
crgwbr
 
[Poland] It's only about frontend
[Poland] It's only about frontend[Poland] It's only about frontend
[Poland] It's only about frontend
OWASP EEE
 
MicroFrontend With Iframes, dirty laundry that can be cleaned
MicroFrontend With Iframes, dirty laundry that can be cleanedMicroFrontend With Iframes, dirty laundry that can be cleaned
MicroFrontend With Iframes, dirty laundry that can be cleaned
Ran Wahle
 
No more excuses left - Webinale 2015 Lunch keynote
No more excuses left - Webinale 2015 Lunch keynoteNo more excuses left - Webinale 2015 Lunch keynote
No more excuses left - Webinale 2015 Lunch keynote
Christian Heilmann
 
Selenium Interview Questions & Answers
Selenium Interview Questions & AnswersSelenium Interview Questions & Answers
Selenium Interview Questions & Answers
Techcanvass
 
DODN2009 - Jump Start Silverlight
DODN2009 - Jump Start SilverlightDODN2009 - Jump Start Silverlight
DODN2009 - Jump Start Silverlight
Clint Edmonson
 
Web-First Design Patterns
Web-First Design PatternsWeb-First Design Patterns
Web-First Design Patterns
Michael Mahemoff
 
Pyramid as a base for higher level frameworks
Pyramid as a base for higher level frameworksPyramid as a base for higher level frameworks
Pyramid as a base for higher level frameworks
Carlos de la Guardia
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
jojule
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Steven Beeckman
 

Similar to Selenium web driver code to handle the following events (20)

What the FUF?
What the FUF?What the FUF?
What the FUF?
 
Handling iFrames in Selenium Based Test Automation.pdf
Handling iFrames in Selenium Based Test Automation.pdfHandling iFrames in Selenium Based Test Automation.pdf
Handling iFrames in Selenium Based Test Automation.pdf
 
Tutorial 8 menu
Tutorial 8   menuTutorial 8   menu
Tutorial 8 menu
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Window object methods (timer related)
Window object methods (timer related)Window object methods (timer related)
Window object methods (timer related)
 
HTML5 Web Messaging
HTML5 Web MessagingHTML5 Web Messaging
HTML5 Web Messaging
 
Talk about html5 security
Talk about html5 securityTalk about html5 security
Talk about html5 security
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.js
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
 
[Poland] It's only about frontend
[Poland] It's only about frontend[Poland] It's only about frontend
[Poland] It's only about frontend
 
MicroFrontend With Iframes, dirty laundry that can be cleaned
MicroFrontend With Iframes, dirty laundry that can be cleanedMicroFrontend With Iframes, dirty laundry that can be cleaned
MicroFrontend With Iframes, dirty laundry that can be cleaned
 
No more excuses left - Webinale 2015 Lunch keynote
No more excuses left - Webinale 2015 Lunch keynoteNo more excuses left - Webinale 2015 Lunch keynote
No more excuses left - Webinale 2015 Lunch keynote
 
Selenium Interview Questions & Answers
Selenium Interview Questions & AnswersSelenium Interview Questions & Answers
Selenium Interview Questions & Answers
 
DODN2009 - Jump Start Silverlight
DODN2009 - Jump Start SilverlightDODN2009 - Jump Start Silverlight
DODN2009 - Jump Start Silverlight
 
Web-First Design Patterns
Web-First Design PatternsWeb-First Design Patterns
Web-First Design Patterns
 
Pyramid as a base for higher level frameworks
Pyramid as a base for higher level frameworksPyramid as a base for higher level frameworks
Pyramid as a base for higher level frameworks
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 

Recently uploaded

Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

Selenium web driver code to handle the following events

  • 1. Selenium Web Driver Code to handle the following events How to handle Frames, iFrames: Frames Code: driver.switchTo().frame("id"); (Where id was the frame id) iFrame Code: WebElement iFrame= driver.findElement(By.(“id”)); (Where id was the iframe id) driver.switchTo().frame(iFrame); How to handle Multiple windows: Multiple windows Code: for(String winHandle : driver.getWindowHandles()) { driver.switchTo().window(winHandle); } driver.manage().window().maximize(); Code for the operations held in new window String winHandleBefore = "Page Title for parent window"; driver.switchTo().window(winHandleBefore);
  • 2. How to handle Alerts: Alert Accept Code: Alert al=d.switchTo().alert(); String s=al.getText(); assertEquals("Expected value in the alert",s); al.accept(); Alert Accept Code: For confirmation alerts with ok and cancel buttons For Alert with click ‘ok’ was same as above For Alert with click ‘Cancel’ button below was the code: Alert al=d.switchTo().alert(); String s=al.getText(); assertEquals("Expected value in the alert",s); al.dismiss(); Insert values in alerts: Alert al=d.switchTo().alert(); String s=al.getText(); assertEquals("Expected value in the alert",s); al.sendKeys(“Text”); al.accept(); How to handle Drag & Drop: WebElement draggable = driver.findElement(By.id("id")); WebElement droppable = driver.findElement(By.id("id")); new Actions(driver).dragAndDrop(draggable, droppable).build().perform(); How to handle Mouse over events: Actions builder = new Actions(d); WebElement tagElement = d.findElement(By.id("id")); builder.moveToElement(tagElement).build().perform(); tagElement.click();
  • 3. Screenshots on Failure: try { Code } catch(Exception e){ File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); String k="C:eclipseScreenshotsMagError.png"; FileUtils.copyFile(scrFile, new File(k)); }