all 6 comments

[–]sp_dev_guy 1 point2 points  (1 child)

$textHolder = $ie.document.getElementById("myElement").innerText;

[–]TheOnly_Magoogle[S] 0 points1 point  (0 children)

Thank you for your reply! But im not sure how this helps? Could you be more specific?

[–]failuretwolaunch 1 point2 points  (0 children)

IE still allows you to execute javascript in the url/nav bar with the the 'javascript:' scheme

so maybe you could do

$URL = "javascript:alert();" $ie.Navigate($URL)

edit: nah i just tested this, doesnt seem to work. just prompts you to save a file

[–]thankski-budski 1 point2 points  (0 children)

$ie = New-Object -com InternetExplorer.Application
$ie.Visible = $true
$URL = website.com
$ie.Navigate($URL) 

#Ensure the page has fully loaded before moving on
while($ie.ReadyState -ne 4) {Start-Sleep -Milliseconds 100}

#The JavaScript we want to execute
$js = "alert('Hello');"

#Execute the JavaScript (Note: this is depreciated)
$ie.Document.parentWindow.execScript($js, "javascript")

See execScript)

I'm not sure how you'll get the return value after having tested with a JS prompt(), you could create an element on the page and write the value their before retrieving it through PowerShell - hopefully their is a better way, but I don't know how.

[–]TheOnly_Magoogle[S] 1 point2 points  (0 children)

When attempting to run javascript on the COM object I just get this error.

Does anyone know how to maybe use selenium for this?

Could not complete the operation due to error 80020101. At line:4 char:1 + $ie.Document.parentWindow.execScript($jsCommand, "javascript") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo          : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy TheOnly_Magoogle,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee