For when you have the tag and you want to know where it is.
(self)
| 98 | self.assertEqual(matching[0].name, 'a') |
| 99 | |
| 100 | def testFindByIndex(self): |
| 101 | """For when you have the tag and you want to know where it is.""" |
| 102 | tag = self.soup.find('a', id="a") |
| 103 | self.assertEqual(self.soup.index(tag), 3) |
| 104 | |
| 105 | # It works for NavigableStrings as well. |
| 106 | s = tag.string |
| 107 | self.assertEqual(tag.index(s), 0) |
| 108 | |
| 109 | # If the tag isn't present, a ValueError is raised. |
| 110 | soup2 = BeautifulSoup("<b></b>") |
| 111 | tag2 = soup2.find('b') |
| 112 | self.assertRaises(ValueError, self.soup.index, tag2) |
| 113 | |
| 114 | def testConflictingFindArguments(self): |
| 115 | """The 'text' argument takes precedence.""" |
nothing calls this directly
no test coverage detected