1. What are the characteristics of JavaScriptAlerts?
- We can not move the pop-up.
- We can not inspect the popup.
- It is black and white
- If it contains only the ok button then it is an alert pop-up.
- If it contains only the ok and cancel buttons, it is a confirmation pop-up.
- If it contains only the Text box, ok and cancel button then it is a prompt pop-up
2. What is an alert on the web page?
- they are normally pop-up dialogue boxes which appear with a message.
- it contains information which users need to interact with.
- There are 3 types of javascript alerts
- Alert (one OK button and message)
- Confirmation (OK and cancel button with the message)
- Prompt (input field with OK and Cancel buttons)
3. How do you handle alerts in Selenium?
- Selenium provides an Alert interface to interact with the alerts.
- first, we must switch to alert using the driver.switchTo().alert().
- Then we can use several methods call accept(), dismiss(), getText()
4. Explain what is accept() and dismiss()?
accept(): used to accept the alert by clicking the OK button.
dismiss(): used to dismiss the alert by clicking on the cancel button.
5. How to verify text in the alert?
Using the getText() method. it retrieves the text of the message in an alert box.
6. How to send data in prompt alert?
using the sendKeys() method we can pass the value we want to send as information in the alert box.
7. How to verify the presence of an alert?
- Use the WebDriverWait class
- use the alertIsPresent() method in ExpectedConditions class.
8. Can you switch from one alert to another?
- You cannot
- first, switch into alert and then switch back to the main window.
- then again switching to alert is the way.
9. Can you handle or disable alerts at the browser level?
No. Selenium cannot handle browser-level alerts. it needs third-party plugins or capabilities.
10. Write Code to click the ok button, cancel button, send data and get the text value of an alert
driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().sendKeys(input value);
driver.switchTo().alert().getText();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().sendKeys(input value);
driver.switchTo().alert().getText();
No comments:
Post a Comment