Thirtyfour: how to find StaleElementReference?

Hi,

(beginner in Rust and Thirtyfour)

I am playing around with thirtyfour and get the following error:

Error: StaleElementReference(WebDriverErrorInfo { status: 404, error: "", value: 
WebDriverErrorValue { message: "stale element reference: stale element not found in the current 
frame\n  (Session info: chrome=132.0.6834.110)", error: Some("stale element reference"), 
stacktrace: Some("#0 0x55a15bcbeda2 <unknown>\n#1 0x55a15b7bda33 <unknown>\n#2 
0x55a15b7c3eeb <unknown>\n#3 0x55a15b7c5a1f <unknown>\n#4 0x55a15b7c5ae5 
<unknown>\n#5 0x55a15b8030bd <unknown>\n#6 0x55a15b82dbf6 <unknown>\n#7 
0x55a15b7fc012 <unknown>\n#8 0x55a15b82dda2 <unknown>\n#9 0x55a15b84ae3e 
<unknown>\n#10 0x55a15b82d957 <unknown>\n#11 0x55a15b7f9aeb <unknown>\n#12 
0x55a15b7fa9a6 <unknown>\n#13 0x55a15bc905ee <unknown>\n#14 0x55a15bc9392f 
<unknown>\n#15 0x55a15bc933ac <unknown>\n#16 0x55a15bc93db9 <unknown>\n#17 
0x55a15bc80bc2 <unknown>\n#18 0x55a15bc94137 <unknown>\n#19 0x55a15bc6814d 
<unknown>\n#20 0x55a15bcaee29 <unknown>\n#21 0x55a15bcaf00f <unknown>\n#22 
0x55a15bcbde99 <unknown>\n#23 0x7f17b2e9c083 <unknown>\n"), data: None } })

This error does not occur instantly but after 20 minutes or so. So the debug cycle is quite long. Is there a way to find out where this error occurs? I have several dozens of WebElement interactions like:

let foo = driver.query(By::Id("foo")).all_from_selector().await?;

... as it is stated in the thirtyfour examples on thirtyfour - Rust

Trying to find the culprit, I changed some of those lines to:

let foo = driver.query(By::Id("foo")).all_from_selector().await;
let foo = match foo {                                                                     
    Ok(foo) => foo,
    Err(error) => {
                dbg!("!Err: {}", error);
                vec![]
    },
};

... but so far, the error message is still the same and no other output is generated.

Is there a better way to find the culprit or am I on the right track and "just" have to do this for all WebElement interactions?

Thanks

You could add some context to errors if you're using anyhow. Otherwise, you should use inspect_err: Result in std::result - Rust.

Here's a playground.