Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Somewhere in HTML, there's a table that looks like this. What I want to do is get the text of the <td class="feature-value"> based on the value of <td class="feature-name">.

HTML
<table>
    <tr>
      <td class="feature-name"> GPU </td>
      <td class="feature-value"> Intel Iris Xe Graphics </td>
    </tr>
    <tr>
      <td class="feature-name"> Memory </td>
      <td class="feature-value"> 512 GB </td>
    </tr>
    <tr>
      <td class="feature-name"> Memory Type </td>
      <td class="feature-value"> SSD </td>
    </tr>
    <tr>
      <td class="feature-name"> Model </td>
      <td class="feature-value"> Huawei MateBook 14 </td>
    </tr>
    <tr>


What I have tried:

Is there a way to do it like that?
Posted
Updated 26-Jan-23 5:56am
Comments
Afzaal Ahmad Zeeshan 25-Jan-23 21:00pm    
What code have you tried to read the value based on the name?
Andre Oosthuizen 26-Jan-23 8:57am    
By using the getText() method in selenium - https://www.browserstack.com/guide/get-text-of-an-element-in-selenium#:~:text=Cross%20Browser%20Compatibility-,getText()%20Method%20in%20Selenium,and%20back%20of%20the%20string.

1 solution

This is a solution:

Python
gpu = driver.find_element(By.XPATH,"//td[@class='feature-name' and contains(.,'GPU')]/following-sibling::td").text
 
Share this answer
 
Comments
Mathew Newton 13-May-23 22:07pm    
Thank you for the hint to use <<element>>.text as I couldn't find this referenced anywhere else and it solved an issue I had been working on for way too long.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900