def test_finds_multiple_kinds_of_nodes_regardless_of_the_context(self): xpath = to_xpath(x.descendant("div")[x.attr("id") == "woo"].anywhere("p", "ul")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Blah") self.assertEqual(inner_text(results[3]), "A list") self.assertEqual(inner_text(results[4]), "A list") self.assertEqual(inner_text(results[6]), "Bax")
def test_finds_all_nodes_when_no_arguments_given_regardless_of_the_context(self): xpath = to_xpath(x.descendant("div")[x.attr("id") == "woo"].anywhere()) results = self.find_all(xpath) self.assertEqual(results[0].tag, "html") self.assertEqual(results[1].tag, "head") self.assertEqual(results[3].tag, "body") self.assertEqual(inner_text(results[5]), "Blah") self.assertEqual(inner_text(results[9]), "A list") self.assertEqual(inner_text(results[12]), "A list") self.assertEqual(inner_text(results[14]), "Bax")
def test_finds_nodes_which_are_exactly_preceding_the_current_node(self): woo_div = x.descendant("p")[x.attr("id").equals("wooDiv")] gorilla = x.descendant("p")[x.attr("title").equals("gorilla")] xpath = to_xpath(woo_div.previous_sibling("p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Bax") xpath = to_xpath(woo_div.previous_sibling("ul", "p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Bax") xpath = to_xpath(gorilla.previous_sibling("ul", "p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "A list") xpath = to_xpath(woo_div.previous_sibling("ul", "li")) results = self.find_all(xpath) self.assertSequenceEqual(results, []) xpath = to_xpath(woo_div.previous_sibling()) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Bax")
def test_finds_nodes_which_are_immediate_siblings_of_the_current_node(self): foo_div = x.descendant("p")[x.attr("id").equals("fooDiv")] monkey = x.descendant("p")[x.attr("title").equals("monkey")] xpath = to_xpath(foo_div.next_sibling("p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Bax") xpath = to_xpath(foo_div.next_sibling("ul", "p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Bax") xpath = to_xpath(monkey.next_sibling("ul", "p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "A list") xpath = to_xpath(foo_div.next_sibling("ul", "li")) results = self.find_all(xpath) self.assertSequenceEqual(results, []) xpath = to_xpath(foo_div.next_sibling()) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Bax")
def test_matches_by_node_name(self): xpath = to_xpath(x.descendant("*")[x.name == "ul"]) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "A list")
def test_returns_the_number_of_elements_in_the_context(self): xpath = to_xpath(x.descendant("p")[x.position() == x.last()]) results = self.find_all(xpath) self.assertEquals(inner_text(results[0]), "Bax") self.assertEquals(inner_text(results[1]), "Blah") self.assertEquals(inner_text(results[2]), "llama")
def test_finds_nodes_regardless_of_the_context(self): foo_div = x.anywhere("div")[x.attr("id").equals("foo")] xpath = to_xpath(x.descendant("p")[x.attr("id").equals(foo_div.attr("title"))]) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Blah")
def test_finds_nodes_that_are_nested_below_the_current_node(self): xpath = to_xpath(x.descendant("p")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Blah") self.assertEqual(inner_text(results[1]), "Bax")
def test_finds_all_nodes_when_no_arguments_given(self): xpath = to_xpath(x.descendant()[x.attr("id").equals("foo")].descendant()) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Blah") self.assertEqual(inner_text(results[4]), "A list")
def test_finds_multiple_kinds_of_nodes(self): xpath = to_xpath(x.descendant("p", "ul")) results = self.find_all(xpath) self.assertEqual(inner_text(results[0]), "Blah") self.assertEqual(inner_text(results[3]), "A list")
def test_returns_the_position_of_elements_in_the_context(self): xpath = to_xpath(x.descendant("p")[x.position() == 2]) results = self.find_all(xpath) self.assertEquals(inner_text(results[0]), "Bax") self.assertEquals(inner_text(results[1]), "Bax")