date change check working
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -109,7 +109,7 @@ async fn scrape_events(client: &fantoccini::Client) -> anyhow::Result<Vec<Econom
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let port = 9515; // pick a port you like
|
||||
let mut chromedriver = start_chromedriver(port);
|
||||
sleep(Duration::from_secs(2)).await; // wait for ChromeDriver to start
|
||||
sleep(Duration::from_secs(1)).await; // wait for ChromeDriver to start
|
||||
|
||||
// Chrome options (non-headless so it opens)
|
||||
let caps_value = serde_json::json!({
|
||||
@@ -161,7 +161,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
vec![]
|
||||
).await;
|
||||
|
||||
for _ in 0..30 {
|
||||
for _ in 0..5 {
|
||||
// Check if the iframe exists
|
||||
let overlay_hidden: bool = client.execute(
|
||||
r#"(() => {
|
||||
@@ -185,6 +185,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
.unwrap_or(false);
|
||||
|
||||
if overlay_hidden {
|
||||
println!("Overlay hidden");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -218,16 +219,30 @@ async fn main() -> anyhow::Result<()> {
|
||||
}})()
|
||||
"#, start_date, end_date);
|
||||
|
||||
let dates_set = client.execute(&set_dates_script, vec![])
|
||||
.await
|
||||
.ok()
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
// Execute JS to set dates and get the raw response
|
||||
let _ = client.execute(&set_dates_script, vec![]).await;
|
||||
|
||||
if dates_set {
|
||||
println!("Dates set successfully from {} to {}", start_date, end_date);
|
||||
// Give React time to process
|
||||
sleep(Duration::from_millis(500)).await;
|
||||
|
||||
// Now read the values
|
||||
let from_date_value: String = client.execute(
|
||||
r#"return document.querySelector('#dtTeletraderFromDate')?.value;"#,
|
||||
vec![],
|
||||
).await?.as_str().unwrap_or_default().to_string();
|
||||
|
||||
let to_date_value: String = client.execute(
|
||||
r#"return document.querySelector('#dtTeletraderEndDate')?.value;"#,
|
||||
vec![],
|
||||
).await?.as_str().unwrap_or_default().to_string();
|
||||
|
||||
println!("From Date: {}", from_date_value);
|
||||
println!("To Date: {}", to_date_value);
|
||||
|
||||
if from_date_value == start_date && to_date_value == end_date {
|
||||
println!("Dates set correctly");
|
||||
} else {
|
||||
println!("Failed to set dates");
|
||||
println!("Date not set correctly");
|
||||
}
|
||||
|
||||
// Hide any reappearing overlay
|
||||
@@ -247,7 +262,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
// Wait a bit for the table to load
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
|
||||
// Find all table rows
|
||||
let rows = client.find_all(Locator::Css(
|
||||
|
||||
Reference in New Issue
Block a user