Alerts

 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?

  1. they are normally pop-up dialogue boxes which appear with a message.
  2. it contains information which users need to interact with.
  3. There are 3 types of javascript alerts
  4. Alert (one OK button and message)
  5. Confirmation (OK and cancel button with the message)
  6.  Prompt (input field with OK and Cancel buttons)
3. How do you handle alerts in Selenium?

  1. Selenium provides an Alert interface to interact with the alerts. 
  2. first, we must switch to alert using the driver.switchTo().alert().
  3. 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?

  1. You cannot
  2.  first, switch into alert and then switch back to the main window. 
  3. then again switching to alert is the way.
9Can 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();

11. You need to retrieve the message in an alert box, without using the getText() method. How will you handle this situation in Selenium IDE

  1. storeAlert() command can be used to retrieve the message from the alert pop-up
  2. The value is stored in a variable that can be returned using a System.out.println statement. 
  3. You can also use assertEquals() to verify this message
  4. The command will read the alert text and store it in a specified variable.storeAlert(variable_name) 
  5. This is used in Selenium IDE 

No comments:

Post a Comment

Cucumber

What is Cucumber? Definition : Cucumber is an open-source tool that supports BDD . Purpose : Bridges the communication gap between business ...