C# With Selenium - Doubt about xPath

Asked

Viewed 395 times

3

I am automating a page function and when it will click on the error image, finally I have tried several things, my doubt is the following the xPath that I am sending is correct?

<div id="toolbar">
        <table cellspacing="1px" cellpadding="1px" width="100%" class="birtviewer_toolbar">
            <tbody><tr><td></td></tr>
            <tr>
                <td width="6px">
                </td><td width="15px">
                   <input type="image" name="toc" src="birt/images/Toc.gif" title="Comutar índice" alt="Comutar índice" class="birtviewer_clickable">
                </td>
                <!--
                <TD WIDTH="6px"/>
                <TD WIDTH="15px">
                   <INPUT TYPE="image" NAME='parameter' SRC="birt/images/Report_parameters.gif"
                        TITLE="Executar relatório"  
                        ALT="Executar relatório" CLASS="birtviewer_clickable">
                </TD>
                <TD WIDTH="6px"/>
                <TD WIDTH="15px">
                   <INPUT TYPE="image" NAME='export' SRC="birt/images/Export.gif"
                        TITLE="Exportar dados"
                        ALT="Exportar dados" CLASS="birtviewer_clickable">
                </TD>
                -->
                <td width="6px">
                </td><td width="15px">
                   <input type="image" name="exportReport" src="birt/images/ExportReport.gif" title="Exportar relatório" alt="Exportar relatório" class="birtviewer_clickable">
                </td>
                <td width="6px">
                </td><td width="15px">
                   <input type="image" name="print" src="birt/images/Print.gif" title="Imprimir relatório" alt="Imprimir relatório" class="birtviewer_clickable">
                </td>

                <td align="right">
                </td>
                <td width="6px">
            </td></tr>
        </tbody></table>
    </div>

Class I need to click

  </td><td width="15px">
               <input type="image" name="exportReport" src="birt/images/ExportReport.gif" title="Exportar relatório" alt="Exportar relatório" class="birtviewer_clickable">
            </td>

xPathdriver.FindElement(By.XPath("//a[./img[@name='exportReport']tr[2]/td[4]/]")).Click();

2 answers

0


Surely your Xpath is not right and is returning null.

One way you can do it is this.

var inputs = browser.FindElementsByTagName("input");
foreach (var item in inputs)
{
    var alt = item.GetAttribute("src");
    if (alt != null && alt.Contains("Exportar relatório"))
    {
        item.Click();
        break;
    }
}
  • Unfortunately it didn’t work.

  • found the input element ? or had some error?

  • returned null in input element

  • I did the debugging step by step, walked 28x the foreach returned ID, but did not enter if, not locating the src element

  • you have to debug and see how the item is being loaded, see other element properties to see if I find the correct one.

  • 1

    I did the mapping, I located a frame, I got inside the frame and I was able to use src thanks for the help

Show 1 more comment

0

Your HTML is poorly formed. You have to put tag endings in the INPUT tags.

The Xpath you are looking for is:

//input[@type='image'][@name='exportReport']

Browser other questions tagged

You are not signed in. Login or sign up in order to post.