Automatically click yes button in ATF

Not applicable

In ATF by using Click component (custom UI), how to click yes button automatically without manual Involvement. 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@Community Alums 

I could see it's a modal.

Did you try to use Click Component (Custom UI) step?

You need to retrieve the HTML elements and then only you can tell ATF what to click.

where are you stuck?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@Community Alums 

Thank you for marking my response as helpful.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Matthew_13
Mega Sage

Hi Buddy,

ATF can’t reliably “see” buttons inside a custom modal with the normal Click component step, so the usual way to automate this is to click it with a client-side script.

In your ATF test, add a step like Run Client Script and click the Yes button from the DOM, for example:

// click the visible "Yes" button in the open modal
var yesBtn = Array.from(document.querySelectorAll('button, a, input'))
  .find(el => ((el.innerText || el.value || '').trim().toLowerCase() === 'yes') &&
              (el.offsetWidth || el.offsetHeight || el.getClientRects().length));

if (yesBtn) yesBtn.click();

That will close the confirmation automatically with no manual involvement.

If you can change the UI, the best long-term fix is to add something stable like an id or data-testid to the Yes button (ex: data-testid="confirm-yes"), then ATF can click it directly without guesswork.

 

@Community Alums - Please mark Accepted Solution and Thumbs Up if you found Helpful

MJG

@Matthew_13 

It would be helpful if you could share a working example of this using Run Client Script step which you mentioned along with screenshots

I couldn't find that step in ATF.

AnkurBawiskar_0-1769091748334.png

 

AnkurBawiskar_1-1769092946044.png

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron

@Community Alums 

I could see it's a modal.

Did you try to use Click Component (Custom UI) step?

You need to retrieve the HTML elements and then only you can tell ATF what to click.

where are you stuck?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Community Alums 

Thank you for marking my response as helpful.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader