From 2a45e4d60793c9b90ec30b30431de699604b9129 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 14 Jul 2019 09:42:20 +0200 Subject: Add dir navigation tests --- tests/utils/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/utils/mod.rs (limited to 'tests/utils') diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs new file mode 100644 index 0000000..b724945 --- /dev/null +++ b/tests/utils/mod.rs @@ -0,0 +1,12 @@ +use select::document::Document; +use select::node::Node; +use select::predicate::Name; +use select::predicate::Predicate; + +/// Return the href attribute content for the closest anchor found by `text`. +pub fn get_link_from_text(document: &Document, text: &str) -> Option { + let a_elem = document + .find(Name("a").and(|x: &Node| x.children().any(|x| x.text() == text))) + .next()?; + Some(a_elem.attr("href")?.to_string()) +} -- cgit v1.2.3