Find a table containing specific text

JXU

I have a table:

 html ='
 <table cellpadding="1" cellspacing="0" width="100%" border="0">
 <tr>
 <td colspan="9" class="csoGreen"><b class="white">Bill Statement Detail</b></td>
 </tr>
 <tr style="background-color: #D8E4F6;vertical-align: top;">
 <td nowrap="nowrap"><b>Bill Date</b></td>
 <td nowrap="nowrap"><b>Bill Amount</b></td>
 <td nowrap="nowrap"><b>Bill Due Date</b></td>
 <td nowrap="nowrap"><b>Bill (PDF)</b></td>
 </tr>
 </table>
 '

I use the codes suggested in this post (XPath matching text in a table - Ruby - Nokigiri). It works fine if I use any words in the first row as the match word, for example "Statement". But it doesn't work if I use words that in the other row, for example "Amount".

doc  = Nokogiri::HTML("#{html}")
doc.xpath('//table[contains(descendant::*, "Statement")]').each do |node|
    puts node.text
end
har07

The contains() function expects a singular value as its first argument. descendant::* may yield multiple elements then causing the function to behave unexpectedly, such as considering only the first element yielded.

Try to change your XPath to be:

doc.xpath('//table[descendant::*[contains(., "Amount")]]').each do |node|
    puts node.text
end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find a table containing specific text

From Dev

Find specific table row containing substring text of a jquery variable of html

From Dev

Find specific table row containing substring text of a jquery variable of html

From Dev

Find the closest table containing a text

From Dev

Find first and last row containing specific text

From Dev

Find cell in html table containing a specific icon

From Java

How do I find all files containing specific text on Linux?

From Dev

Using jQuery to find list items containing specific text in nested lists

From Dev

Unable to find a button wrapping elements containing specific text for Selenium testing

From Dev

Count of cells containing specific text

From Dev

Count of cells containing specific text

From Dev

How to find specific row in ng-table by text [protractor]

From Dev

Find files containing a text but not the second

From Dev

Find a string in a specific table

From Dev

Find and drop a field containing a specific string

From Dev

Find and drop a field containing a specific string

From Dev

rails find records containing specific word

From Dev

Find exclude path containing specific files

From Dev

How to find all domains containing specific string

From Dev

jQuery: Find all DIVs containing specific elements

From Dev

Scrape a script tag containing specific text

From Dev

Extract sentence from text containing a specific phrase

From Dev

Select div class containing specific text

From Dev

Scrape a script tag containing specific text

From Dev

Remove href containing specific text part

From Dev

Delete lines containing specific character in text file

From Dev

SQL : Select a table name containing specific string

From Dev

Regex to find text containing new line

From Dev

Find out text length containing emojis

Related Related

  1. 1

    Find a table containing specific text

  2. 2

    Find specific table row containing substring text of a jquery variable of html

  3. 3

    Find specific table row containing substring text of a jquery variable of html

  4. 4

    Find the closest table containing a text

  5. 5

    Find first and last row containing specific text

  6. 6

    Find cell in html table containing a specific icon

  7. 7

    How do I find all files containing specific text on Linux?

  8. 8

    Using jQuery to find list items containing specific text in nested lists

  9. 9

    Unable to find a button wrapping elements containing specific text for Selenium testing

  10. 10

    Count of cells containing specific text

  11. 11

    Count of cells containing specific text

  12. 12

    How to find specific row in ng-table by text [protractor]

  13. 13

    Find files containing a text but not the second

  14. 14

    Find a string in a specific table

  15. 15

    Find and drop a field containing a specific string

  16. 16

    Find and drop a field containing a specific string

  17. 17

    rails find records containing specific word

  18. 18

    Find exclude path containing specific files

  19. 19

    How to find all domains containing specific string

  20. 20

    jQuery: Find all DIVs containing specific elements

  21. 21

    Scrape a script tag containing specific text

  22. 22

    Extract sentence from text containing a specific phrase

  23. 23

    Select div class containing specific text

  24. 24

    Scrape a script tag containing specific text

  25. 25

    Remove href containing specific text part

  26. 26

    Delete lines containing specific character in text file

  27. 27

    SQL : Select a table name containing specific string

  28. 28

    Regex to find text containing new line

  29. 29

    Find out text length containing emojis

HotTag

Archive