Saturday, June 22, 2024

Handling Image

 

Handling Image:


Common Actions:

  1. Click the Image
  2. Get the 'src' Attribute of the Image
  3. Check if the Image is Displayed
  4. Check if the Image is Enabled
  5. Get the Alt Text of the Image

package WebelementsBasics;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class ImageBasics {

 

            public static void main(String[] args) throws InterruptedException {

                        //open chrome browser

                                                System.setProperty("webdriver.chrome.driver", ".\\Drivers\\chromedriver.exe");

                                                WebDriver  driver =  new ChromeDriver();

 

                                                Thread.sleep(3000);

                                                driver.navigate().to("file:///C:/brahma/Practise/qtp%20practise/web%20apps/ALL%20Web%20objects.html");

 

 

                                                //  check 'Penguins' Image is displayed  by id

                                                boolean imgDisplayed =    driver.findElement(By.name("myimage")).isDisplayed();

                                                //                        true

                                                    //  String, int, boolean

 

                                                System.out.println("isDisplayed="+imgDisplayed);

                                                // isDisplayed=  true

                                               

                                               

 

                                                //HW get 'width' attribute value for image ?

 

                                                //HW get 'height' attribute value for image ?

 

                                                //HW get 'alt ' attribute value for image ?

                                                //   alt = alternate text

                                               

                                                // HW get 'src' attribute value for image ?

 

                                                //  dont have  name , id , class --- >  xpath, cssSelector

                                               

 

 

            }

 

}

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...