From d4758562227f35ac7405d87c120a4e0b56b335ac Mon Sep 17 00:00:00 2001 From: "Gerard Castillo Lasheras (BI X)" Date: Sun, 28 Jan 2024 13:45:23 +0400 Subject: [PATCH] wait for timeframe and use wait on tab default timeout --- src/timetable.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index aef88d9..93d7bdb 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -86,6 +86,7 @@ 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") @@ -93,8 +94,6 @@ pub fn search_timetable( .wait_until_navigated() .unwrap(); - sleep(Duration::from_secs(wait)); - println!("waiting for search page"); tab.wait_until_navigated() .unwrap() @@ -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);