Jump to content
egnew

TEdgeBrowser Script to Set Password and Click Submit

Recommended Posts

Posted (edited)

I am emailed html files that link to a Cisco "Secure Email Encryption Service".  I can load the downloaded html into a TEdgeBrowser, manually enter the password, click the button, and access the content using document.innerHTML.  I need to be able to get the program to fill in the password and click the submit button.  Nothing happens when I execute the code I expect to work.

 

I created the following a test form which uses the same input and button:

<form action="https://www.google.com" method="post">
Password: <input name="key1" id="passwordInput1" autocomplete="off" type="password"><br>
<input type="submit" "id="text_i18n.authframe.safr.button.openonline" value="Open Online" name="openButton">
</form>

 

I set the password using:

document.getElementById("passwordInput1").value = 'mypass'

 

I click the button using:

document.querySelector("input[type=submit]").click();

 

Everything works as expected with my test form but I am unable to accomplish this with the "Secure" form.  This is likely because the values are embedded in other elements. 

 

The structure is very complex and I am leaving out many table rows and other details.  I think I have identified the important elements as shown below:

<table id="outerTable"

<tbody>

<tr>

<td id="iframelocation">

<iframe id="authFrame"

#document

>html>

<body>

<form>

<table class="mainWIndow">

<tbody>

<tr>

<td id="heightControl"

<table>

<tbody>

<tr>

  <td>

  <table id=borderTable">

  <tbody>

    <tr>

      <td id=passwordEntry1">

      <p>

      <input size="20" maxlength="127" name="key1" id="passwordInput1" placeholder="Secure Email Encryption Service Password" title="Enter your password here" autocomplete="off" type="password" style="width: 100%;">

       </input>

 

The button is in <td id="openButtonLocation"> in <td id="buttonContainer" eventually going batck to <tr id=buttonRow", etc. and is defined as:

<input type="submit" id="text_i18n.authframe.safr.button.openonline" value="Open Online" name="openButton" onclick="openOnline()" class="btn">

 

The ExecuteScript seems to only execute one line of javascript so I am not sure how to access the field and the button.

What do I need to do differently?

 

I would also like to be able to accomplish this using the types (password and submit) instead of the Id once I get this working.

 

Thanks

 

Edited by egnew
Add details

Share this post


Link to post
On 4/13/2022 at 9:23 AM, egnew said:

I set the password using:

document.getElementById("passwordInput1").value = 'mypass'

 

I click the button using:

document.querySelector("input[type=submit]").click();

Can you post your Delphi code that you are using to execute those two lines of script?

 

document.querySelector returns the first submit button, which might not be the one you are wanting to target (the page could potentially contain more than one form).  If the ID is known you could try targeting the button in a more specific way:

document.getElementById("text_i18n.authframe.safr.button.openonline").click();

 

Thought:  ExecuteScript may be asynchronous, so you may need to combine the two lines of script to execute as a single statement - I don't know your existing code, but something like:

 

s := 'document.getElementById("passwordInput1").value = "mypass"; document.getElementById("text_i18n.authframe.safr.button.openonline").click();';

Browser1.ExecuteScript(s);

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×