mardi 27 mars 2018

c# how can i check if img file exist in div class

The problem is that I can not check if there is a file on the page. There is a code in which this image is present:

<div class="specials-block">

<a href="/ru/actions/443">
<div class="specials-block-item icons-guide ico1" data-amount="5" data-toggle="tooltip" data-html="true" data-placement="bottom" title="" data-original-title="">
</div>
</a>
<div class="specials-block-item">
<img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAEsA......8X2F0UZvgYHv0AAAAASUVORK5CYII=">
</div>
</div>

And the code in which this image is missing:

<div class="specials-block">

<a href="/ru/actions/443">
<div class="specials-block-item icons-guide ico1" data-amount="5" data-toggle="tooltip" data-html="true" data-placement="bottom" title="" data-original-title="">
</div>
</a>
<div class="specials-block-item">

</div>
</div>

In order to check whether this image is present, I do a check:

var intelAtom = driver.FindElement(By.XPath("/html/body/div[5]/div[4]/div/div[1]/div[1]/div[5]/div[1]/div/img[@src='------------------------------']"));
   if (intelAtom.Displayed)
   {
       MessageBox.Show("All is OK");
   }
   else
   {
       MessageBox.Show("WTF O_o , displayed enother Icon");         
   }

but I need to check both the presence of the image and if the img dislayed that the desired image is displayed. Somthing like this:

if (driver.FindElement(By.XPath("/html/body/div[5]/div[4]/div/div[1]/div[1]/div[5]/div[1]/div/img")).Displayed)
{
    var intelAtom = driver.FindElement(By.XPath("/html/body/div[5]/div[4]/div/div[1]/div[1]/div[5]/div[1]/div/img[@src='------------------------------']"));
    if (intelAtom.Displayed)
    {
          MessageBox.Show("All is OK");
    }
    else
    {
          MessageBox.Show("WTF O_o , displayed enother Icon");
    }
 }
 else
 {
     MessageBox.Show("WTF O_o , Icon Intel Pentium is't displayed");
 }

But if I start second query, it was failed, because it didn't find img file

driver.FindElement(By.XPath("/html/body/div[5]/div[4]/div/div[1]/div[1]/div[5]/div[1]/div/img"))

.

Perhaps someone knows how to build the right query in order to determine whether the image was displayed on the page and the correct image was displayed

Aucun commentaire:

Enregistrer un commentaire