Showing posts with label Selenium. Show all posts
Showing posts with label Selenium. Show all posts

How to handle Alert in Selenium

Handle alerts

driver.switchTo().Alert();

alert.accept()// clicked on ok

alert.dismiss(); //clicked on cancel

for example:

public void alert(){
  String str=driver.switchTo().alert().getText();
  System.out.println(str);
  driver.switchTo().alert().accept();
  //driver.switchTo().alert().dismiss();

 }

Assert and Verify Commands


What is the difference between assert and Verify Commands?

Ans:
There are two mechanisms for validating elements that are available on the application under test. The first is assert: this allows the test to check if the element is on the page. If it is not available, then the test will stop on the step that failed. The second is verify: this also allows the test to check whether the element is on the page, but if it isn't, then the test will carry on executing.