简体   繁体   中英

How to find other elements using xpath using one element

Hi I have a html page like below:

<tr>
    <td class = "sdfgg" >
     <nobr> 3000 </nobr>
    </td>
    <td class = "retre" >
    <nobr> Comm error </nobr>
    </td>
</tr>
<tr>
    <td class ="fdhdf" >
    <nobr> Time: </nobr>
    </td>
    <td class ="csfds" >
    <nobr> 10:00PM </nobr>
    </td>
    <td class ="hdfh" >
    <nobr> Data code: </nobr>
    </td>
    <td class ="dfhfd" >
    <nobr> 456 </nobr>
    </td>
</tr>

I need to find all other elements using element "3000" which is event id. I find this element as follows:

$"//nobr[text()='{eventId}']" which is nothing but $"//nobr[text()='3000']"

I can also find Comm error by using event id in xpath as below:

$"//td/nobr[text()='{eventID}']/parent::td/following-sibling::td/nobr"

How do I find remaining elements using the same event id?. Could someone please help? Other elements to find using '3000' are: "Time", "10:00 PM" , "Data code", "456" The page being dynamic i cannot use class attribute.

The following x-paths may help you.

To find the element comm error

//td/nobr[normalize-space(text())='3000']/parent::td/following-sibling::td/nobr

To find other elements

//td/nobr[normalize-space(text())='3000']/../../following-sibling::tr[1]/td/nobr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM