Home > database >  Selenium web automation using python: How can I handle table using selenium to find a particular row
Selenium web automation using python: How can I handle table using selenium to find a particular row

Time:01-27

Following is a piece of code, I have copied for a record(row). I want to search for selenium1 from the below code and delete that record for the table. I have shared the screenshot of how the record looks in the table. Also ID for each record is different. So, I want to delete record based on matching text. Please help

<tr  id="S2D10925" onm ouseover="javascript:this.className='hilightrow';" onm ouseout="javascript:this.className='evenrow';" onclick="javascript:selectNode('S2D10925');">
        <td align="left">
        &nbsp;
        <img src="../images/icons/destinations\email3.png" style="vertical-align:middle;" width="16" 
        height="16">&nbsp;
        SELENIUM1
        </td>
        <td nowrap="nowrap" align="left">Automation1</td>
        <td nowrap="nowrap" align="left">INTERNET</td>
        <td nowrap="nowrap" align="left">INTER_PROVIDER</td>
        <td align="left">[email protected]</td>
        <td align="left">[email protected]</td>
        <td align="left">EMAIL</td>
        <td nowrap="nowrap" align="left">(UTC-10:00) Hawaii</td>
        <td nowrap="nowrap" align="left">Enabled</td>
</tr>

enter image description here

CodePudding user response:

I would go with XPath. Implementation will be different depending on library you are using, but XPath is supported by underlying Webdriver.

Example XPath which would get you tr node containing td with given text

    //tr[//td[contains(text(),'Automation1')]]

Here is a Codepen using your html fragment:

https://codepen.io/chm-dev-the-selector/pen/dyVdLOa

If you are not familiar with XPath I highly recommend this resource: https://devhints.io/xpath I found it very helpful and time effective resource if you want to get to the point, especially with XPath testbed (provided on the page).

Also found this on similar topic: https://www.guru99.com/using-contains-sbiling-ancestor-to-find-element-in-selenium.html

  •  Tags:  
  • Related