Skip to content

Commit

Permalink
wait for timeframe and use wait on tab default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardcl committed Jan 28, 2024
1 parent b29c197 commit d475856
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/timetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ pub fn search_timetable(
.unwrap();

let tab = browser.new_tab().unwrap();
tab.set_default_timeout(Duration::from_secs(wait));

println!("navigating to renfe timetable search page");
tab.navigate_to("https://www.renfe.com/es/es/viajar/informacion-util/horarios")
.unwrap()
.wait_until_navigated()
.unwrap();

sleep(Duration::from_secs(wait));

println!("waiting for search page");
tab.wait_until_navigated()
.unwrap()
Expand Down Expand Up @@ -139,21 +138,24 @@ pub fn search_timetable(
println!("searching timetable");
tab.press_key("Enter").unwrap();

sleep(Duration::from_secs(wait));

// wait on navigating and prepare search in result page
println!("got timetable page");
let html = tab
.wait_until_navigated()
let html = tab.wait_until_navigated().unwrap();

println!("wait for timetable iframe");
sleep(Duration::from_secs(wait));

let table_content = html
.wait_for_elements_by_xpath(r#"//*[@id="contenedor"]"#)
.unwrap()
.find_element_by_xpath(r#"//*[@id="contenedor"]"#)
.first()
.unwrap()
.get_content()
.unwrap();

println!("loading timetable");

let parsed_html = Html::parse_document(&html);
let parsed_html = Html::parse_document(&table_content);

let resum_selector = make_selector(r#"tr.odd"#);
let total_tracks = parsed_html.select(&resum_selector);
Expand Down

0 comments on commit d475856

Please sign in to comment.