Omnitica

Problems with _IEFormElementSetValue and javascript

20 posts in this topic

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

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

There are jQuery events attached to the element. You will need to trigger the Change event via jQuery. I'll get back to you if I come up with a workable solution.

1 person likes this

Share this post


Link to post
Share on other sites
21 minutes ago, Danp2 said:

There are jQuery events attached to the element. You will need to trigger the Change event via jQuery. I'll get back to you if I come up with a workable solution.

Thank you Danp2. I appreciate the effort.

Share this post


Link to post
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()')

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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.

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

$(".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

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

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

Share this post


Link to post
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")

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Cool... glad you were able to figure it out. That likely would have been my next suggestion. ;-)

The issue is that the display value is being shown in a Span element, not in the actual Select element.

Share this post


Link to post
Share on other sites

Yes indeed.

 

Thank you so much for your effort Danp2, you really helped me out here :)

Now I can get back to finishing my script!

Have a good day / evening.

 

Cheers!

 

Share this post


Link to post
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

  • Similar Content

    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • electrons
      By electrons
      hi  , hope  you all doing well 
       cant find any elements on the page ?  and the right click mouse dont work too?
      iam trying with more than method , i need help please!!
       

    • ur
      By ur
      I have kept below line to wait for IE to load the site completely and continue.
      _IELoadWait($oIE)
       
      But, the code is continuing without waiting for it and I my execution is failing as the elements are not loaded completely.

       
      Any suggestions for alternate code to wait for the browser to load completely?
       
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help