In Page Object factory:
By popup=By.xpath("//button[test()='NO THANKS']");
public List<WebElement> getPopUpSize(){
return driver.findElements(popup);
}
public WebElement getPopUp(){
return driver.findElement(popup);
}
Calling above methods into Testcase:
LandingPage l = new LandingPage(driver);
if(l.getPopUpSize().size()>0)
{
l.getPopUp().click();
}
I didn't understand why do we have to create a list just to cancel single pop up?