Selenium find iframe inside second tr that table as another tr that contains specific text

Issue

Not sure if the title is clear.

I have the following table:

<table>
    <tbody>
        <tr>
            <td>
                <div>Text to Find</div>
            </td>
        </tr>
        <tr>
            <td>
                <iframe></iframe>
            </td>
        </tr>
    </tbody>
</table>

and I have several of this blocks inside the application I am testing (this is simplified)

I want to get the iframe that is inside the "Text to Find" that this changes on each table that contains the iframe.

Is it possible? I have try something like this but isn’t working:

//table[contains(.,'Text to Find')]/tbody/tr[2]/td/iframe

Solution

You are hard coding the row number in the x-path //table[contains(.,'Text to Find')]/tbody/tr[2]/td/iframe.

Your can try the following x-path.

//table/tbody/tr/td/div[contains(.,'Text to Find')]//iframe

Answered By – Murthi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published