How to interact with buttons in ExtJS’s MessageBox element?

I have a Ext.MessageBox which appears when user clicks a button on my desired url.

Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?',function(btnText){
        if(btnText === "no"){

        }
        else if(btnText === "yes"){
             // Do Something
        }
    }, this);
}

I want to test ‘yes’ and ‘no’ buttons on this message window. As I have no id set for it can anyone tell me how to access these buttons?

I tried something like

WebElement y = driver.findElement(By.xpath("//a[2]/span/span/span[2]"));

But it didn’t work. I have checked other similar questions on stack overflow as well but it didn’t wok for me. Kindly help.

Answer

I assume you’re talking about such kind of MessageBox element:

enter image description here

Since extjs generates element IDs on the fly, it’s not so easy to locate one.

But nevertheless there are some patterns which can help you to interact with buttons:

So what you need to do is first to locate element with help of implicit waiting and then click it:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement yesButton = wait.until(
        ExpectedConditions.visibilityOfElementLocated(By.LinkText("Yes")));
yesButton.click();

Leave a Reply

Your email address will not be published. Required fields are marked *