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

Time:06-28

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

CodePudding user response:

You can try below xPath

//div[contains(Text(), 'Text to Find')]/../../following-sibling::tr/td/iframe

CodePudding user response:

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
  • Related