Question: I am currently working on creating a script that will test the functionality of a website. Currently i'm blocked by a popup message that appears when certain conditions are met, when that popup message appears my script fails, if i add something like `driver.findElement(By.xpath("//div[4]/div/div/div/div/div/button")).click();`
the script fails when the popup does not appear.
My question is: Is there a way to check "If the button exists then click button x if not move forward". I know after what action (click) the message appears/does not appear.
Keep in mind that i'm now learning java and selenium.

Answer: 
Banu 

You are right, You should use if else condition.
Because you exactly know in which condition pop up appears and you can use pop up text in if condition.

By 

```
driver.switchTo().alert().getText();  

```
Use Alert class to handle Popups 

Alert alert = driver.switchTo().alert();  

 alert.accept();