Selenium Exercise 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Exercise 3:

package automation_testing;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class Exercise3

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

System.setProperty("webdriver.chrome.driver", "C:\\Users\\omkar\\OneDrive\\Documents\\
Selenium\\chromedriver-win64\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.get("https://web-locators-static-site-qa.vercel.app/Image");

driver.manage().window().maximize();

WebElement twoEyesImage = driver.findElement(By.xpath("//img[@alt=\"image_screen\"]"));

Thread.sleep(2000);

boolean isDisplayed = twoEyesImage.isDisplayed();


if (isDisplayed)

String srcValue = twoEyesImage.getAttribute("src");

String altValue = twoEyesImage.getAttribute("alt");

System.out.println("Image src: " + srcValue);

System.out.println("Image alt: " + altValue);

else

System.out.println("The 'two eyes' image is not displayed.");

driver.close();

}
Output:

You might also like