Jump to content

Problems with _IEFormElementSetValue and javascript


Omnitica
 Share

Recommended Posts

Hello!

I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.


I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
See image 1.

However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
See image 2.

As you can see the value is 3982,4545     ( name , time )

But when I try to change the value of it by doing:

#include <IE.au3>

Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded")
Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm")
Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper")
_IEFormElementSetValue($oInput, "3982,1337")

The box doesn't get its new value. I  can see in the source that it's changed though.
See image 3.

 

However, if I do: 

#include <IE.au3>

Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded")
Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm")
Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper")
_IEFormElementSetValue($oInput, "3982,1337")

$oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page

The box gets its new value after the page reloads by the theForm.submit() function. 
This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.

Maybe someone knows how I can do this? Looking forward to an answer! 
Thanks in advance.

 

Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.

 

1.PNG

2.PNG

3.PNG

Link to comment
Share on other sites

The site is likely using a Javscript framework, such as Node.js or React. These will obscure the code, use hidden objects, etc like you are seeing. This is probably going to be difficult for us to assist you with since the site is private.

First step would be to identify the framework being used.

Link to comment
Share on other sites

18 minutes ago, Danp2 said:

The site is likely using a Javscript framework, such as Node.js or React. These will obscure the code, use hidden objects, etc like you are seeing. This is probably going to be difficult for us to assist you with since the site is private.

First step would be to identify the framework being used.

Thanks for the quick reply! 

Sent you a P.M

Link to comment
Share on other sites

This (possible) solution came from this prior discussion. I'm unable to get this page to render properly in IE. Therefore, I'm unable to test the following code and you will likely need to adjust or adapt it to fit your actual environment --

#include <ie.au3>

Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded")
Local $oDocument = _IEDocGetObj($oIE)
Local $oWindow = $oDocument.ParentWindow

$oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; a reference to the eval method

Sleep(2000) ; give a little time to the browser to create above variables within the javascript environment.

$JSeval = $oIE.Document.body.JSeval ; a reference to the eval javascript method from within AutoIt

$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)")[0] = 10')
$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)").change()')

 

Link to comment
Share on other sites

13 hours ago, Danp2 said:

This (possible) solution came from this prior discussion. I'm unable to get this page to render properly in IE. Therefore, I'm unable to test the following code and you will likely need to adjust or adapt it to fit your actual environment --

#include <ie.au3>

Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded")
Local $oDocument = _IEDocGetObj($oIE)
Local $oWindow = $oDocument.ParentWindow

$oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; a reference to the eval method

Sleep(2000) ; give a little time to the browser to create above variables within the javascript environment.

$JSeval = $oIE.Document.body.JSeval ; a reference to the eval javascript method from within AutoIt

$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)")[0] = 10')
$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)").change()')

 

Hey, thank you for your help. Again, much appreciated.

I'm guessing I need to add Local $oDocument = _IEDocGetObj($oIE)  to get a reference.

I'm having trouble understanding the java functions: 

$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)")[0] = 10')
is this the function that sets the value of the box?

 

$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)").change()')
And this is the function that trigger the change?

Link to comment
Share on other sites

2 minutes ago, Danp2 said:

Yes, the first call sets the value of the input element. This could also be done with _IEFormElementSetValue if you can get a reference to the element. The second call triggers the change event for all matching elements.

Did you try running the code as posted? If so, what was the outcome?

I tried running the script, but no success . The value doesn't change. However I'm curious if the 
$JSeval('$(".input-group .form-control:not(:first-child):not(:last-child)")[0] = 10')
refers to the actual input box. As there are many boxes with the same class. Maybe I'm wrong.

Link to comment
Share on other sites

You could try this yourself if you can open the page in a non-embedded IE. Hit F12 to open the developers tools. Then try entering the command

$(".input-group .form-control:not(:first-child):not(:last-child)")[0] = 10

from the console. If that doesn't work, then perhaps the page is rendering differently under IE (I used FF to come up with the CCS selector).

Link to comment
Share on other sites

$(".input-group .form-control:not(:first-child):not(:last-child)").change()

Strangely enough this sets the value of the

<input type="hidden" name="ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" id="content_ctrl_ucServiceTime_rpServicetimes_edtHiddenResourceHelper_0" value="4448,6767">

to the value that is in the input box, which is 6767. Kind of opposite of what we're trying to do.

 

Also,

$(".input-group .form-control:not(:first-child):not(:last-child)")[0] = 10

Doesn't change the value for me, somehow. But I can still use  _IEFormElementSetValue which I know works.

Edited by Omnitica
Link to comment
Share on other sites

Which element are you updating with IEFormElementSetValue? If you mean,

ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper

then that probably isn't the optimal solution and may not work as expected.

Try this one from the developer console --

$('.input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), .input-group .form-control:not(:first-child):not(:last-child)')[0].value=10

 

Link to comment
Share on other sites

7 minutes ago, Danp2 said:

Which element are you updating with IEFormElementSetValue? If you mean,

ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper

then that probably isn't the optimal solution and may not work as expected.

Try this one from the developer console --

$('.input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), .input-group .form-control:not(:first-child):not(:last-child)')[0].value=10

 

Yes! Now we're getting somewhere. The value changes. But now, how to change the first part of the value,  value="4448,6767">. Or rather the combobox that is before the inputbox.

Note: I was previously using the 

ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper

for  _IEFormElementSetValue 

Edited by Omnitica
Link to comment
Share on other sites

Now try entering

$('.input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), .input-group .form-control:not(:first-child):not(:last-child)').change()

This should cause the change event to trigger, force the value to reflect properly as if you had typed it in manually.

What have you tried with the combobox?

Link to comment
Share on other sites

27 minutes ago, Danp2 said:

Now try entering

$('.input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), .input-group .form-control:not(:first-child):not(:last-child)').change()

This should cause the change event to trigger, force the value to reflect properly as if you had typed it in manually.

What have you tried with the combobox?

With this the:


<input type="hidden" name="ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" id="content_ctrl_ucServiceTime_rpServicetimes_edtHiddenResourceHelper_0" value="4448,6767">

Changes accordingly whats was changed into the box. Great!

 

But now I'm looking for a way to change the option in the combobox, which is defined by  value="4448,6767">   (4448)
4448 is the id of a user.

I just used  _IEFormElementSetValue  on the  ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper.
And set the value to "4448,6767" But then I need to reload the page for the changes to happen.

A similar approach like the 

$('.input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), .input-group .form-control:not(:first-child):not(:last-child)')[0].value=10

perhaps.

Edited by Omnitica
Link to comment
Share on other sites

Try the following and let me know if it works --

#include <ie.au3>

Local $oIE = _IEAttach("UR-000000")
Local $oDocument = _IEDocGetObj($oIE)
Local $oWindow = $oDocument.ParentWindow

$oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; a reference to the eval method

Sleep(2000) ; give a little time to the browser to create above variables within the javascript environment.

$JSeval = $oIE.Document.body.JSeval ; a reference to the eval javascript method from within AutoIt

$oSelect = $JSeval('$(".bootstrap-select > select")[0]')
_IEFormElementOptionSelect($oSelect, "4673")

 

Link to comment
Share on other sites

Hmm, did not work to change in the actual combobox, but the value changes in

<input name="ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" id="content_ctrl_ucServiceTime_rpServicetimes_edtHiddenResourceHelper_0" type="hidden" value="4673,5656">

 

Edited by Omnitica
Link to comment
Share on other sites

However, doing a

#include <ie.au3>

Local $oIE = _IEAttach("UR-000000")
Local $oDocument = _IEDocGetObj($oIE)
Local $oWindow = $oDocument.ParentWindow

$oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; a reference to the eval method

Sleep(2000) ; give a little time to the browser to create above variables within the javascript environment.

$JSeval = $oIE.Document.body.JSeval ; a reference to the eval javascript method from within AutoIt

$oSelect = $JSeval('$(".bootstrap-select > select")[0]')
_IEFormElementOptionSelect($oSelect, "4673")
$JSeval('$(".bootstrap-select > select").change()')

solved it!

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...