Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
PLAYWRIGHT testing - How to skip to the next action if a click on a button is not possible (is not present)?

as anticipated in the question, I'd like to know if is possible to attempt a click action on a button, but if it's not in the page then the test skip that action (without being stucked or throwing an error) and continue to the next one. To be more specific, I have a modal where I can add rows to a table, but what I'd like to do is to add a new row only if a given button in the modal is not present, while if it's present the action would be to press first on that button and then proceeding to add a new row.

I ask you if it's possible because I'd like to avoid conditional statements during the test. Just let me know, thank you in advance :)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can check if the element is present then do something if not then do nothing or something else.

 const modal = page.locator('modal-selector');
    
 if (await modal.isVisible()) {
   // do thing
 } else {
   // do another thing
 }

about 4 years ago · Juan Pablo Isaza Report

0

const locator = page.locator("some selector");
if (locator.count() > 0) {
  // found locator, do something
} else {
  // not found, do something else
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!