Jump to content
Sign in to follow this  
tom13

cannot set $oDoc.cookie

Recommended Posts

tom13

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
MrMitchell

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
  • Like 1

Share this post


Link to post
Share on other sites
tom13

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
DaleHohm

Also, check this out:

Dale

  • Like 1

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
tom13

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
DaleHohm

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
tom13

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
DaleHohm

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
  • Like 1

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  

  • Similar Content

    • Seminko
      By Seminko
      Wrote a script that grabs all of the IP addresses from Netflix's IP log, checks the IPs and returns suspicious activity.
      Everything works as it should but only when _IECreate is set to visible. When visible is set to false, it fails to login for some reason.
      Any ideas what might cause it and/or how to circumvent that?
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • hemichallenger
      By hemichallenger
      Hello,
      If anyone can help, it would be greatly appreciated. The code is just an example and similar to the issue with an internal webpage. I'm trying to autofill than click the submit button. I get the same error running the script.
      _IEFormElementSetValue, $_IESTATUS_InvalidObjectType
      IEGetObjById, $_IESTATUS_NoMatch
      Is it possible to edit the <textarea></textarea>  field with AutoIt?  If anyone could assist me on how. Than I could have a better understanding and chance in figuring it out on my main script. Thank you
      #include <IE.au3> Local $oIE1 = _IECreate ("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea") _IELoadWait($oIE1) local $oFormCollection = _IEFormGetCollection($oIE1,0) local $oid = _IEGetObjByid($oFormCollection, "iframeResult") _IEFormElementSetValue($oid, "test") sleep (2000) Local $oIE2 = _IECreate ("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_scripts_intro") _IELoadWait($oIE2) $oForm2 = _IEFormGetCollection($oIE2,0) $oClickMe = _IEGetObjById($oForm2, "demo") _IEAction($oClickMe, "focus") _IEAction($oClickMe, "click")
    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

×