How to click on Yes No button on an alert (rather than Ok/Cancel) using selenium automation?
You can simply click on Yes button. (No need to switch to alert) :
Code :
new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Yes']/parent::button"))).click();
You can use a parameterized function to Click on Yes/No.In case you want to click on Yes, use: ClickYesNoButton("Yes");
For No, call function as : ClickYesNoButton("No");
Code below:
public void ClickYesNoButton(String yesOrno){ String myXpath = "//span[text()='XXXX']"; driver.findElement(By.xpath(myXpath.replace("XXXX", yesOrno))).click(); }
It's not Javascript alert
.
Use this xpath to click that button
"//span[normalize-space()='Yes']/.."