stevepryde/thirtyfour

Is it possible to load two pages in parallel?

ArbilGit opened this issue · 5 comments

Hi! First of all, let me say that - having worked with selenium across multiple languages - your crate is the most fun!

Is it possible to load two pages in parallel, in two tabs in a single webdriver, and await both navigations? I've never succeeded in doing that in other selenium implementations.

This code seems to load the pages sequentially:

let caps = DesiredCapabilities::chrome();
let driver = Arc::new(WebDriver::new("http://localhost:4444", &caps).await?);
let driver2 = driver.clone();
tokio::spawn(async move {
    //longish loading website to see if parallel
    driver2.get("https://www.ebay.com").await;
});

driver
    .in_new_tab(|| async { driver.get("https://www.google.com").await })
    .await?;

Thanks!

Selenium only operates on one tab at a time and you have to issue commands to switch between them. So working on multiple tabs simultaneously is not possible. At least not without switching contexts before every command.

If you just want a slow page to load in the background that might be possible. By default selenium will wait for a page to finish loading when you issue a get command. But you can change this by setting the page load strategy.

https://www.selenium.dev/documentation/webdriver/page_loading_strategy/

There's no rust example obviously but it should be fairly straightforward to apply this in thirtyfour.

You would then want to start the page loading then immediately open a tab, and start a new page loading.

Unfortunately with the eager page load strategy in place it's now up to you to wait for the desired elements to show up in order to know when the page has finished loading.

It might be more trouble than its worth.

Thank you very much the detailed reply. I suspected the one-page-at-a-time design of selenium cannot be circumvented. Do you know if CDP can provide "navigation finished" callbacks/events for two tabs in parallel? That would allow implementing the parallel async navigation

Unfortunately I haven't used CDP very much so I'm not sure. If you do find a way to do it I would be interested to know.

I'll report back if I find a way to make it work. Thanks for your help!