Sign in to follow this  
Followers 0
tom13

cannot set $oDoc.cookie

8 posts in this topic

#1 ·  Posted (edited)

I'm trying to first get a cookie and then replace a certain server Id with a new one. This is to test each application server for our internal application.

The following is my function of interest:

Func checkAppServer($id)

debug("checking app server for id " & $id)

;access application with app server cookie
ShellExecute("iexplore.exe", "about:blank")
WinWait("Blank Page")
Local $oIE = _IEAttach("about:blank", "url")
_IELoadWait($oIE)
_IENavigate($oIE, "https://application.example.com")
If @error Then
alert("Login checker failed to access application.")
Return
EndIf

;get the document
Local $oDoc = _IEDocGetObj($oIE)
If @error Then
alert("Login checker failed to get the document object.")
Return
EndIf

;get current cookies
$newCookies = $oDoc.cookie
debug("current cookie string: " & $newCookies)

;replace all app server IDs with this ID
For $sServerId In $aAppServerIds
If $sServerId == $id Then ContinueLoop

debug("checking if we are currently on server " & $sServerId)

$newCookies = StringReplace($newCookies, $sServerId, $id, 0, 0)
If @extended Then
debug("replaced old server id " & $sServerId & " to new server id " & $id)
debug("new cookies string: " & $newCookies)
EndIf
Next

;ensure that we are now on the server of interest
If Not StringInStr($newCookies, $id) Then
alert("LoginChecker failed to navigate to server with id " & $id & ". Please fix the script!")
Exit
EndIf

debug("overwriting document.cookie")
$oDoc.cookie = $newCookies
debug("new document.cookie: " & $oDoc.cookie)

Exit

;verify HTTP body

EndFunc

The following output is returned:

checking app server for id ffffffffaf1c7718

current cookie string: usernameType=student; COOKIE_CONSENT_ACCEPTED=true; NSC_100732.qspe1_wjq1c.hspvq=ffffffffaf1c771d45525d5f4f58455e445a4a42378b; JSESSIONID=5EB0C22CD06E6D904653F663670B3056.root; session_id=EF0ABD73D15B5E4431CD59107946E9A9; s_session_id=0D26A888B87A5CF9D07020CF5B5A5955

checking if we are currently on server ffffffffaf1c771b

checking if we are currently on server ffffffffaf1c771a

checking if we are currently on server ffffffffaf1c771d

replaced old server id ffffffffaf1c771d to new server id ffffffffaf1c7718

new cookies string: usernameType=student; COOKIE_CONSENT_ACCEPTED=true; NSC_100732.qspe1_wjq1c.hspvq=ffffffffaf1c771845525d5f4f58455e445a4a42378b; JSESSIONID=5EB0C22CD06E6D904653F663670B3056.root; session_id=EF0ABD73D15B5E4431CD59107946E9A9; s_session_id=0D26A888B87A5CF9D07020CF5B5A5955

checking if we are currently on server ffffffffaf1c776c

overwriting document.cookie

new document.cookie: usernameType=student; COOKIE_CONSENT_ACCEPTED=true; NSC_100732.qspe1_wjq1c.hspvq=ffffffffaf1c771d45525d5f4f58455e445a4a42378b; JSESSIONID=5EB0C22CD06E6D904653F663670B3056.root; session_id=EF0ABD73D15B5E4431CD59107946E9A9; s_session_id=0D26A888B87A5CF9D07020CF5B5A5955

This means that:

  • the cookie is retrieved correctly

  • the ID of interest is replaced correctly, and set to $newCookies

  • when executing $oDoc.cookie = $newCookies, $oDoc.cookie does not actually change
Why does it appear impossible to set $oDoc.cookie? Edited by tom13

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

When you set cookie as stated on this page, they use escape to encode the string. Maybe that would help?

And a UDF:

Edited by MrMitchell
1 person likes this

Share this post


Link to post
Share on other sites

When you set cookie as stated on this page, they use escape to encode the string. Maybe that would help?

And a UDF:

Thanks, I was hoping this would be it. Unfortunately encoding the string before setting $oDoc.cookie appears to have no effect at all. Same story when I also decode the cookie before retrieving it.

Any other ideas? :(

Share this post


Link to post
Share on other sites

Also, check this out:

Dale

1 person likes this

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Also, check this out:

Dale

Hmm, that is somewhat confusing. Do you have any idea how I would now replace the entire cookie?

Share this post


Link to post
Share on other sites

Hmm, that is somewhat confusing. Do you have any idea how I would now replace the entire cookie?

I think it's pretty clear - pair by pair.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think it's pretty clear - pair by pair.

Dale

That doesn't seem to work, for some reason it adds the cookie and duplicates it instead of replacing it.

My code:

$oDoc.cookie = $sName & "=" & $sVal

Resulting cookie string:

NSC_100732.qspe1_wjq1c.hspvq=ffffffffaf1c771845525d5f4f58455e445a4a42378b; JSESSIONID=037CE036F417243612A9766EC519EDF5.root; NSC_100732.qspe1_wjq1c.hspvq=ffffffffaf1c771b45525d5f4f58455e445a4a42378b; JSESSIONID=0EC325282EF8D5E4811AA444E64AA2FF.root

Obviously, only the first "NSC_100732.qspe1_wjq1c.hspvq" cookie should be there, not the second (this is the old one).

Edited by tom13

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Figure out what you are doing differently from this example:

#include <IE.au3>

$oIE = _IECreate("www.google.com")

$oIE.document.cookie = "test_cookie=one; path=/;"
ConsoleWrite($oIE.document.cookie & @CRLF)

$oIE.document.cookie = "test_cookie=two; path=/;"
ConsoleWrite($oIE.document.cookie & @CRLF)

_IEQuit($oIE)

Dale

Edited by DaleHohm
1 person likes this

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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
Sign in to follow this  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • Omnitica
      By Omnitica
      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.
       



    • kawliga751
      By kawliga751
      I have a workplace GUI that has a search field function that pulls up customer records to allow changes. I am attempting to 1)LOGIN 2)Enter Search field, enter a number and then {ENTER} 3)change specific field once customer record loads. I have very limited experience in GUI manipulation but I am able to login using the below:
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/ASAG/index.htm') Call ("RacksheetSignIn") Func RacksheetSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/RackSheets/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc However I can't seem to use the _IEGetObjByName or Mouseclick to focus on the search field to allow me to enter my search criteria. When I "inspect element" in the Search field I get the attached:
       
      Any help would be MUCH appreciated
       
       
       

    • TotalAuto
      By TotalAuto
      Hi All
      I am new to AutoIT, its community, and pretty much programming in general. 
      After a bit of online research, I decided to focus on AutoIT as my first programming attempt as it seems quite powerful and amazing once you become advanced at it. I have read some introductory pdfs which where good, including from the guy I think who invented it. I also watched various sketchy youtube videos, checked out the forum etc. I have to admit it's a bit confusing starting off but I reckon if I just keep pushing forward with continual hard work I can only get better.  
      My first AutoIT project has been to open Internet Explorer and automatically log into Twitter to save doing it manually. I plan to run this after windows start up via task scheduler. I am using the #include <IE.au3> UDF but for some reason about 20% of the time I receive the following orange error notifications at the bottom of the editor (pic attached). When it happens the IE browser just doesn't open but the program continues to run which mucks up the script. 
      Does anyone know why this is happening and how it can be fixed? Also is there some other better, less error prone way, to open IE and automatically log in?
      I have tried to use the Get Object NAME and ID commands to insert the username and password (i.e. the xxxxxxxxxx's) but when I right click to use "Inspect element" there is no name or id. It seems to be some sort of java script reference?
      I am using Windows 7 with latest updates and Internet Explorer version 11.
      As this is my first post I hope I am following protocols, and if not, please let me know and I will improve.
      Thanks

    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?