thirtyfour icon indicating copy to clipboard operation
thirtyfour copied to clipboard

Send_keys issue

Open msdevega opened this issue 1 year ago • 5 comments

I use this code to fill a login box in a web page: use std::error::Error; use thirtyfour::prelude::*;

#[tokio::main] async fn main() -> Result<(), Box<dyn Error + Send + Sync>> { // define the browser options let mut caps = DesiredCapabilities::chrome(); // to run Chrome in headless mode // caps.add_arg("--headless=new")?; // comment out in development caps.add_arg("--enable-automation")?; // comment out in development // initialize a driver to control a Chrome instance // with the specified options let driver = WebDriver::new("http://localhost:9515", caps).await?;

// visit the target page
driver.goto("https://programme.openhouse.org.uk/login").await?;

// let login = driver.find(By::Css("input#email-input")).await?; login.send_keys("[email protected]").await?; println!("login");

// close the browser and release its resources // driver.quit().await?; Ok(()) }

The code execute without any error, but the login name is written incomplete in the web page: [email protected] and not [email protected] as expected. Any idea of how to solve this issue. I use: ChromeDriver 131.0.6778.108 (3b014839fbc4fb688b2f5af512d6ce312ad208b1-refs/branch-heads/6778@{#2393}) Google Chrome 131.0.6778.139 cargo 1.83.0 (5ffbef321 2024-10-29) thirtyfour v0.35.0

Best regards

msdevega avatar Dec 22 '24 09:12 msdevega

I'm not a dev, but maybe try adding some wait before and after sending keys:

tokio::time::sleep(Duration::from_millis(20)).await;
// some io code
tokio::time::sleep(Duration::from_millis(20)).await;

9teta avatar Jan 01 '25 21:01 9teta

I tried adding the sleeps before and after send_keys with the same result, the login name is incomplete in the web page. Captura de pantalla 2025-01-02 a las 10 24 56

msdevega avatar Jan 02 '25 09:01 msdevega

Try clicking the input before sending keys to it.

BlinkyStitt avatar Feb 03 '25 06:02 BlinkyStitt

I use this code to fill a login box in a web page: use std::error::Error; use thirtyfour::prelude::*;

#[tokio::main] async fn main() -> Result<(), Box<dyn Error + Send + Sync>> { // define the browser options let mut caps = DesiredCapabilities::chrome(); // to run Chrome in headless mode // caps.add_arg("--headless=new")?; // comment out in development caps.add_arg("--enable-automation")?; // comment out in development // initialize a driver to control a Chrome instance // with the specified options let driver = WebDriver::new("http://localhost:9515", caps).await?;

// visit the target page
driver.goto("https://programme.openhouse.org.uk/login").await?;

// let login = driver.find(By::Css("input#email-input")).await?; login.send_keys("[email protected]").await?; println!("login");

// close the browser and release its resources // driver.quit().await?; Ok(()) }

The code execute without any error, but the login name is written incomplete in the web page: [email protected] and not [email protected] as expected. Any idea of how to solve this issue. I use: ChromeDriver 131.0.6778.108 (3b014839fbc4fb688b2f5af512d6ce312ad208b1-refs/branch-heads/6778@{#2393}) Google Chrome 131.0.6778.139 cargo 1.83.0 (5ffbef321 2024-10-29) thirtyfour v0.35.0

Best regards

can you please use code block qoutes?

println!("Hello!")

for example can be created with: ```rs println!("Hello!") ```

vrtgs avatar Feb 03 '25 07:02 vrtgs

can you try doing this?:

use std::error::Error;
use thirtyfour::prelude::*;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    // define the browser options
    let mut caps = DesiredCapabilities::chrome();
    // to run Chrome in headless mode
    // caps.add_arg("--headless=new")?; // comment out in development
    caps.add_arg("--enable-automation")?; // comment out in development
    // initialize a driver to control a Chrome instance
    // with the specified options
    let driver = WebDriver::new("http://localhost:9515", caps).await?;

    // visit the target page
    driver.goto("https://programme.openhouse.org.uk/login").await?;

    let login = driver.find(By::Css("input#email-input")).await?;
    for c in "[email protected]".chars() {
        login.send_keys(c).await?;
        tokio::time::sleep(std::time::Duration::from_millis(1)).await
    }
    println!("login");

    // close the browser and release its resources
    // driver.quit().await?;
    Ok(())
}

because this seems to be a website issue rather than any issue I know of, as it stands calling send_keys, just sends a send_keys command to the webdriver, there is no logic that send individual keys to the browser with a timeout

vrtgs avatar Feb 03 '25 07:02 vrtgs