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

    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks
    • Seminko
      By Seminko
      I am now able to populate the dropdown menus at https://www.tipcars.com/.
      The dropdowns are dynamic and do not have a Text value, only ids.
      Is there a way to get all the available options from a dropdown?
      $url = "https://www.tipcars.com/" $oIE = _IECreate($url) _IELoadWait($oIE) $oDownloadSamples = _IEGetObjById($oIE, "homepage_vyhl_frm_vozidlo") _IEFormElementOptionSelect($oDownloadSamples, "C") Above code, populates ID 'C' into the 'druh' dropdown, which results in selecting 'užitkové'. 
      Is there a way so I can grab all of the options from the dropdown menu? I could easily grab all the IDs but I am afraid they will change in the future so I would much rather match the text titles and assign the option IDs grabbed from site.
      This is what the options are according to Chrome:
      <select class="w1"id="homepage_vyhl_frm_vozidlo"name="homepage_vyhl_frm_vozidlo"onchange="try{NABIDKA_VOZIDEL_FORMULAR.naplnSelectZnacka('homepage_vyhl_frm');GLOBAL.pocetInzerceHZ('homepage_vyhl_frm','vozidlo');}catch(ex){odeslatJsChybu('formHOMEPAGE onChange 1: ' + ex.message, 'formHomePage onChange 1', -1);}"> <option value="A" style="color: black;">osobní a terénní (56 334)</option> <option value="C" style="color: black;">užitkové (4 333)</option> <option value="D" style="color: black;">nákladní (3 742)</option> <option value="E" style="color: black;">autobusy (56)</option> <option value="F" style="color: black;">obytné (373)</option> <option value="G" style="color: black;">přívěsy (1 179)</option> <option value="J" style="color: black;">motorky (780)</option> <option value="S" style="color: black;">pracovní stroje (605)</option> <option value="L" style="color: black;">ostatní (235)</option></select> Also, this cannot be grabbed by _INetGetSource.
      Thanks