selenium - what is difference between Alert al=new Alert(driver); al.accept() and driver.switchTo().alert().accept(); -


alert al=new alert(driver);  

al.accept(); driver.switchto().alert().accept();

there isn't difference between two. 1 cleaner other.

take following code consideration:

driver.switchto().alert().accept(); 

this code tell driver switch active alert present within driver, accept it. in 1 easy line of code.

now take code consideration:

alert al = new alert(driver); al.accept(); 

here have create alert object, pass in driver parameter constructor, , accept alert.

the first code segment preferred because way developers have set driver methods can chain commands together. allows use method, pass return method without having tell our code create object it. object still created, (as developers) not have know existence. therefore making our code easier read , maintain.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -