Web custom login with JavaScript

Resolved

Web custom login with JavaScript

avatar

We are trying to automate the login on the HPE Virtual Connect web management UI. The current configuration includes a compulsory banner that requires the user to click on a checkbox before enabling the username/password fields, hence autofill is not an option in this specific case.

We have identified the ID of the checkbox and created a single line JavaScript code that will simulate the mouse click. We have checked that the code is working when, while having opened the web session as embedded in RDM, we fire the web browser developer tools (F12) and execute the single line code from the debugger. However, when we insert the exact same line in Authentication / Script / Custom script the code apparently it's not executed, or maybe it is executed before the whole page is loaded, or maybe it has failed.

How is it supposed to work a custom script? Is it injected in the page after the web page has been completely loaded? Is there a way to check/debug that the code has been effectively executed, or if it has incurred in an error? We don't find a proper documentation for this feature, nor it's very clear how the three tabs in Authentication interact / mutually exclude among them.

Thanks.

All Comments (5)

avatar

Hello,

Thank you for reaching out to us regarding this,

Could you please specify the version of RDM you are currently using?
What type of data source are you using?

I'm also wondering if it would be possible for you to share the script and if the website you are attempting this with is public? If it is public, are you able to share the URL?

Let me know,

Best regards,

Samuel Dery

avatar

Hello Samuel,

We are using version 2023.3.20.0 with MSSQL data source. We can certainly share the script, it's just one line as follows:

document.mainPage.frames['loginBody'].acceptBanner();

with acceptBanner()being the function called on the checkbox click event.

The URL is not public, unfortunately, and requires access to an HPE Virtual Connect hardware. By default, the web interface goes straight to the typical username/password, but in case the device has been configured in showing a banner before logging in, the text boxes for the mentioned fields are disabled until you click on a specific checkbox shown under the banner, as an acknowledgement that you have read the banner content.

Independently from the fact the banner is shown or less, the web page has a couple of nested iframes that load asynchronously from the initial page. We tried to define an arbitrary (long enough) delay, but it didn't work. We also tried to change the code as follows, mimicking what another user in this forum did for 365 login:

function waitForElement(selector) {
  return new Promise(resolve => {
    if (document.querySelector(selector)) {
      return resolve(document.querySelector(selector));
    }
    const observer = new MutationObserver(mutations => {
      if (document.querySelector(selector)) {
        observer.disconnect();
        resolve(document.querySelector(selector));
      }
    });
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
  });
}

// Simulate click on the accept notice checkbox
waitForElement("iframe[id='loginBody']").then((element) => {
  element.contentWindow.acceptBanner();
});


I am not personally well versed on JavaScript, but without knowing when and if the code is injected/fired, and no (known) way to debug it, it is very difficult to understand what's going on.

Thanks.

avatar

Hello,

Thank you for your reply,

I see, I would like to confirm if you encounter the same behavior when adding the script in a separate JavaScript type entry, once created, if you go back into your Website entry Properties under the "Events" -> "After Open" section and use the "Macro/Script/Tool" option then point to the entry you just created.

Does it still not work as expected?

Let me know,

Best regards,

Samuel Dery

avatar

Hello,

I've done some testing with my colleagues, and we've confirmed using a test website that it seems to be working as expected.

We currently suspect the issue is with your script, is it working as expected when used outside RDM?

In our testing, we used this website:
https://juice-shop.herokuapp.com/#/

The script we used is the following:
function clickDismissButtonSpecific() {
  window.addEventListener('load', () => {
    // Specifically target buttons that have an aria-label of 'Close Welcome Banner'
    const button = document.querySelector('button[aria-label="Close Welcome Banner"]');
    if (button) {
      console.log('Dismiss button found and clicked.');
      button.click(); // Click the 'Dismiss' button
    } else {
      console.log('Dismiss button not found.');
    }
  });
}// Call the function
clickDismissButtonSpecific();

Perhaps you can modify it to target the button specific to your website and see if it works for you.

Best regards,

Samuel Dery

avatar

Your custom script is likely being executed before the page is fully loaded, which could explain why it’s not working as expected. Custom scripts typically run after the page load, but depending on how the page elements are structured, timing might be an issue. You can try adding a delay or using window.onload to ensure the page is fully loaded before executing the script. Additionally, using console.log within your script can help debug it and check if the code executes properly. Ensure the script is placed in the correct tab for it to interact as expected. My cousin was preparing for an important project when she suddenly had to submit an essay. Feeling overwhelmed, she turned to this https://academized.com/professional-essay-writers platform for professional essay writing help. The writer assigned to her project was knowledgeable and delivered an exceptional essay that exceeded her expectations. The essay was well-structured, engaging, and thoroughly edited. She received high praise from her professor and could focus on her project without any stress. This service truly delivers on its promises.