Verify Image Presence in Web Page using Selenium WebDriver

JavaScript executor is one of the most useful features of Selenium WebDriver. It allows Selenium user to perform many complex scenarios easily. This post covers one such important scenario. Selenium verify image present example using WebDriver. We have used JavaScript executor in WebDriver Java code here to verify if image is present in a web page.Selenium Verify Image Present Example

Perform below steps to see how this can be done.

  • Find a web page which contains a broken image. Or you can create it easily in your local system.
  • Open your class file and write a code to locate an image such as below. You can use different image attributes(Eg. alt, name etc.) to locate image using XPath.
  • Write a JavaScript executor code to verify if image is present in page. It can be done as shown in below code.
  • Write a code to print desired output as per image presence state.
  • Done. Your method should look like below after performing above steps.
  • Run your test. It should identify if image is displayed in web page and will print appropriate result in console.

We hope the above Selenium verify image present example would be helpful to you in your test automation activities. Let us know this works out for you.

  1. susheel
    • Maharshi
    • jp
  2. Niklas
    • Mohammed
  3. Puneeth
  4. lakshmi
    • Surya
  5. athira
  6. Ranjith
    • null
    • rahul
  7. sathish
  8. Ramana
  9. Ruchi
  10. Sahil
    • sunil
  11. Shanti Nath
  12. Hiral Gsoani
  13. Raja
  14. DS
  15. Nilam Patel

Leave a Reply

Your email address will not be published.