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

    • 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