mattsse / chromiumoxide

Chrome Devtools Protocol rust API
Apache License 2.0
712 stars 69 forks source link

Error when trying to click: Node is either not visible or not an HTMLElement #218

Closed juddbaguio closed 1 month ago

juddbaguio commented 1 month ago

Description

When attempting to click on an element selected using find_xpath, an error occurs stating that the node is either not visible or not an HTMLElement. This issue occurs in the verify_license function.

Steps to Reproduce

  1. Navigate to the page where the element is located.

    {
    let (mut browser, mut handler) =
        Browser::launch(BrowserConfig::builder().with_head().build().unwrap()).await?;
    
    let handle = tokio::task::spawn(async move {
        while let Some(h) = handler.next().await {
            if h.is_err() {
                break;
            }
        }
    });
    
    let tab = browser
        .new_page("https://online.prc.gov.ph/verification")
        .await?;
    
    tab.wait_for_navigation().await?;
    }
  2. Attempt to click on the element with the ID select2-verLProf-container using the following code:
    let select_container = "//*[@id=\"select2-verLProf-container\"]";
    let verl_prof_container = tab.find_xpath(select_container).await?;
    verl_prof_container.click().await?;

Expected Behavior

The element should be clicked without any errors.

Actual Behavior

An error is thrown indicating that the node is either not visible or not an HTMLElement.

Here is the screenshot of an element I am trying to click on: image

juddbaguio commented 1 month ago

Issue Resolved: Element Not Fully in View for Click Action

We have successfully resolved the issue where the element was not fully in view when attempting to perform a click action in the browser. The root cause was identified as the element not being completely rendered and visible at the time of interaction.

To address this, we implemented a delay using

tokio::time::sleep(tokio::time::Duration::from_millis(400)).await; 

to ensure that the browser has sufficient time to render the element fully before any actions are attempted. This delay allows for the necessary UI updates and ensures that the element is interactable.

We have tested this solution extensively, and it has proven to be effective in resolving the clicking issue by ensuring the element is fully visible and interactable.

Thank you for your patience while we addressed this matter.