Skip to main content

Alert Handling in Selenium Web Driver

Alert have only Accept and Cancel button which which have only text in title of alert, Accept the alert, cancel the alert and provide some value/text in the alert. following is the process how to handle the alert with Selenium Web driver.
Here when user click on the change text then a alert box is opening which needed to handle.
Here in this we need to get the title of the alert, Cancel the alert, Provide value for alert text box and then accept the alert.
here you can change the URL in which you are checking and corresponding the locators to locate the web elements.
getText(): to get the alert title
sendkeys(): to provide the input to the alert
accept(): Accept the alert box
dismiss(): cancel the alert box

below is the sample code to show an alert box


 In the below code of selenium, You can have the idea regarding the get text and accept the alert box.


Now in below code sample you can understand the dismiss function of alert




Below is the code to understand this dismiss() function

 
 Now in below sample code i will let you know that how sendkeys() function will work in alert



Below is the code to understand this function

 

Comments

Popular posts from this blog

What is API?

In general way, API (Application Programming Interface) is the intermediate software which is useful for two applications to communicate. API is the tool which is used for interaction of two applications. If developer developing any software which have multiple blocks (Modules) than developer use APIs to put them together.

Ad-Hoc Testing

Ad-Hoc Testing is the testing type which is performed without any proper procedure and without any Requirement Specification. Ad-Hoc testing is totally informal testing which have intension to break the application as early as possible and found important defect early.  In Ad-hoc testing tester do not have any test cases so only the users who have very high knowledge regarding the application only they can perform Ad-Hoc Testing.

Smoke Testing

In Smoke Testing, Testing team check the key feature or key bugs of the software. Smoke testing ensure that critical functionality of the software is working fine.If key features are not working then it is no needed to test the overall functionality because it is just waste of time. In Smoke Testing, test team check the basic feature of the software and if basic feature is not working it means software is broken very badly and further testing is unnecessary. If Smoke Testing failed then it is declared that build is unstable and revert back to developer team until smoke test is pass.