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

153
Views
How to verify Image is visible/exists on front end using <img src> or <a href> tag

Does anyone know how I can verify if an image exists using its <a href> or <img src>? I can only verify by its class such as:

it('Verifying vertical product', () => {
    cy.get('.stage --vertical').should('be.visible')
})

but I want to know how to verify with img src or href tag. thank you

Full HTML:

<a href="haigclub.diageoplatform.com/en/our-whisky/haig-club-clubman"> 
  <img style="margin: auto; display: block;" class="stage__image" 
    src="haigclub.diageoplatform.com/user/themes/haig/images/bottle.png"> 
</a>

enter image description here

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

0

A more explicit test might select href and .find() the img, to avoid the problem of returning multiple images.

cy.get('a[href^="haig-club-clubman"]')
  .find('img')                             // find inside previous selector (a[href])
  .should('have.attr', 'src')
  .and('include', 'bottle.png')            // explicit test of src attribute
about 4 years ago · Juan Pablo Isaza Report

0

If I understand correctly, you are looking for

cy.get('a[href="..."]')

Similarly

cy.get('img[src="..."]')

where you should add the appropriate text instead of ...

Of course, follow with .should('be.visible').

If you want to use a partial match, you can use

cy.get('img[src$="bottle.png"]')  // NOTE src$= 
about 4 years ago · Juan Pablo Isaza Report

0

If you want to assert the image with the image name you can do something like:

cy.get('img').invoke('attr', 'src').should('include', 'bottle.png')
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!