-2

I want to validate "img" properties from the following html code[please refer image]

enter image description here

Code Here

//table[@class='row header-logo' and @style='border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%']

Kindly help me to get the exact xpath to validate "img" properties by title, alt,src

Community
  • 1
  • 1

1 Answers1

0

First, locate the <img> with this XPath:

//img[@alt='Intel']

Explained:

  • // - Selects first matching node
  • img[@alt='Intel'] - Select <img> where alt equals string 'Intel'

Then, use IWebElement.GetAttribute to get the <img> attributes to validate:

IWebDriver driver;

try
{
    // locate image
    IWebElement image = driver.FindElement(By.XPath("//img[@alt='Intel']"));

    // get image attributes
    string title = image.GetAttribute("title");
    string alt = image.GetAttribute("alt");
    string src = image.GetAttribute("src");

    // validate title, alt, and src
    // EX: Assert.AreEqual("Intel", title);
}
catch (NoSuchElementException)
{
    // image does not exist, handle accordingly
}
budi
  • 6,351
  • 10
  • 55
  • 80