Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Paste data on clipboard into Internet Explorer form field

Reply
 
Old 12-09-2007   #1 (permalink)
eXtech


 
 

Paste data on clipboard into Internet Explorer form field

I have the code to launch a specific webpage with one field.
I have the code to store the required data on the clipboard.

What I don't have is an effective way to paste the data into the form field.

Example:
---------------------------------
$ie = New-Object -com InternetExplorer.Application
$ie.navigate(<URL>)
$ie.visible = $true

## Code here that reads a text file and parses data

# The following command stops me cold.
$ie.ExecWB(13,2) #should paste clipboard data into field.

If I walk my program line by line (ie: enter by hand), then the data gets
pasted. As part of a function, an error is thrown.

Thanks
Extech

My System SpecsSystem Spec
Old 12-09-2007   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Paste data on clipboard into Internet Explorer form field

eXtech wrote:
Quote:

> I have the code to launch a specific webpage with one field.
> I have the code to store the required data on the clipboard.
>
> What I don't have is an effective way to paste the data into the form field.
>
> Example:
> ---------------------------------
> $ie = New-Object -com InternetExplorer.Application
> $ie.navigate(<URL>)
> $ie.visible = $true
>
> ## Code here that reads a text file and parses data
>
> # The following command stops me cold.
> $ie.ExecWB(13,2) #should paste clipboard data into field.
>
> If I walk my program line by line (ie: enter by hand), then the data gets
> pasted. As part of a function, an error is thrown.
>
> Thanks
> Extech
This *might* help:
http://scriptolog.blogspot.com/2007/...web-forms.html

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 12-10-2007   #3 (permalink)
Kuma


 
 

Re: Paste data on clipboard into Internet Explorer form field

On Dec 10, 12:23 pm, "Marco Shaw [MVP]"
<marco.shaw@_NO_SPAM_gmail.com> wrote:
Quote:

> eXtech wrote:
Quote:

> > I have the code to launch a specific webpage with one field.
> > I have the code to store the required data on the clipboard.
>
Quote:

> > What I don't have is an effective way to paste the data into the form field.
>
Quote:

> > Example:
> > ---------------------------------
> > $ie = New-Object -com InternetExplorer.Application
> > $ie.navigate(<URL>)
> > $ie.visible = $true
>
Quote:

> > ## Code here that reads a text file and parses data
>
Quote:

> > # The following command stops me cold.
> > $ie.ExecWB(13,2) #should paste clipboard data into field.
>
Quote:

> > If I walk my program line by line (ie: enter by hand), then the data gets
> > pasted. As part of a function, an error is thrown.
>
Quote:

> > Thanks
> > Extech
>
> This *might* help:http://scriptolog.blogspot.com/2007/...web-forms.html
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShellhttp://www.microsoft.com/mvp
>
> PowerGadgets MVPhttp://www.powergadgets.com/mvp
>
> Blog:http://marcoshaw.blogspot.com- Hide quoted text -
>
> - Show quoted text -
Quick example.

$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible=$true
$ie.navigate("www.Google.com")
($ie.Document.GetElementByID("q")).Value='Blah Blah Blah'

Check your explorer and you will see the text pasted into the search
field. If you wonder where the "q" came from just view source on the
web page and search for <input type="text" Within the INPUT tag look
for the ID="" filed and use that ID. Hope that helps.
My System SpecsSystem Spec
Old 12-10-2007   #4 (permalink)
Kuma


 
 

Re: Paste data on clipboard into Internet Explorer form field

On Dec 10, 3:08 pm, Kuma <kumasa...@xxxxxx> wrote:
Quote:

> On Dec 10, 12:23 pm, "Marco Shaw [MVP]"
>
>
>
>
>
> <marco.shaw@_NO_SPAM_gmail.com> wrote:
Quote:

> > eXtech wrote:
Quote:

> > > I have the code to launch a specific webpage with one field.
> > > I have the code to store the required data on the clipboard.
>
Quote:
Quote:

> > > What I don't have is an effective way to paste the data into the form field.
>
Quote:
Quote:

> > > Example:
> > > ---------------------------------
> > > $ie = New-Object -com InternetExplorer.Application
> > > $ie.navigate(<URL>)
> > > $ie.visible = $true
>
Quote:
Quote:

> > > ## Code here that reads a text file and parses data
>
Quote:
Quote:

> > > # The following command stops me cold.
> > > $ie.ExecWB(13,2) #should paste clipboard data into field.
>
Quote:
Quote:

> > > If I walk my program line by line (ie: enter by hand), then the data gets
> > > pasted. As part of a function, an error is thrown.
>
Quote:
Quote:

> > > Thanks
> > > Extech
>>
Quote:

> > Marco
>
Quote:

> > --
> > Microsoft MVP - Windows PowerShellhttp://www.microsoft.com/mvp
>
Quote:

> > PowerGadgets MVPhttp://www.powergadgets.com/mvp
>
Quote:

> > Blog:http://marcoshaw.blogspot.com-Hide quoted text -
>
Quote:

> > - Show quoted text -
>
> Quick example.
>
> $ie = New-Object -ComObject InternetExplorer.Application
> $ie.visible=$true
> $ie.navigate("www.Google.com")
> ($ie.Document.GetElementByID("q")).Value='Blah Blah Blah'
>
> Check your explorer and you will see the text pasted into the search
> field. If you wonder where the "q" came from just view source on the
> web page and search for <input type="text" Within the INPUT tag look
> for the ID="" filed and use that ID. Hope that helps.- Hide quoted text -
>
> - Show quoted text -
Woops forgot to post the rest. If you have PSCX you can use the Get-
Clipboard cmdlet.
$text = Get-Clipboard
($ie.Document.GetElementByID("q")).Value=$text
Sorry about that.
My System SpecsSystem Spec
Old 12-10-2007   #5 (permalink)
eXtech


 
 

Re: Paste data on clipboard into Internet Explorer form field



"Kuma" wrote:
Quote:

> Quick example.
>
> $ie = New-Object -ComObject InternetExplorer.Application
> $ie.visible=$true
> $ie.navigate("www.Google.com")
> ($ie.Document.GetElementByID("q")).Value='Blah Blah Blah'
>
> Check your explorer and you will see the text pasted into the search
> field. If you wonder where the "q" came from just view source on the
> web page and search for <input type="text" Within the INPUT tag look
> for the ID="" filed and use that ID. Hope that helps.

This is the error I get:
You cannot call a method on a null-valued expression.
At $profile:61 char:30
+ ($ie.Document.GetElementByID( <<<< "H1")).Value=$bc
My System SpecsSystem Spec
Old 12-10-2007   #6 (permalink)
Shay Levi


 
 

Re: Paste data on clipboard into Internet Explorer form field

Extech,

The page elements might not be available because the didn't load already.
Use $ie.busy (or ReadyState) to detect if the page finished loading and then
try to set the element value:

$ie.navigate(<URL>)
#while($ie.ReadyState -ne 4) {sleep 1}
while($ie.busy) {sleep 1}
$ie.Document.GetElementByID("H1").Value=$bc



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


Quote:

> I have the code to launch a specific webpage with one field. I have
> the code to store the required data on the clipboard.
>
> What I don't have is an effective way to paste the data into the form
> field.
>
> Example:
> ---------------------------------
> $ie = New-Object -com InternetExplorer.Application
> $ie.navigate(<URL>)
> $ie.visible = $true
> ## Code here that reads a text file and parses data
>
> # The following command stops me cold.
> $ie.ExecWB(13,2) #should paste clipboard data into field.
> If I walk my program line by line (ie: enter by hand), then the data
> gets pasted. As part of a function, an error is thrown.
>
> Thanks
> Extech

My System SpecsSystem Spec
Old 12-10-2007   #7 (permalink)
eXtech


 
 

Re: Paste data on clipboard into Internet Explorer form field

I figured it out. It has to do with the ReadyState. ReadyState must be
equal to 4 before pasting any data to form elements.

Thanks
My System SpecsSystem Spec
Old 02-11-2008   #8 (permalink)
pjo


 
 

Re: Paste data on clipboard into Internet Explorer form field


eXtech;1428273 Wrote:
Quote:

> I figured it out. It has to do with the ReadyState. ReadyState must
> be
> equal to 4 before pasting any data to form elements.
>
> Thanks
Hi

I am trying almost the same.

while($ie.ReadyState -ne 4) {start-sleep -Milliseconds 100}

but the execution repeats here, $ie.ReadyState never becomes ready.
Running Vista .NET 3.5. running it in the PowerShell Plus.
What would be the cause ?

pjo


--
pjo
http://www.techtalkz.com - Technology and Computer Troubleshooting Forums

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Data Execution Prevention Error in Internet Explorer Vista security
Clipboard Vitual PC 2007 Can't paste Virtual PC
When I try to paste into internet explorer-stops working Vista performance & maintenance
internet explorer blocks printing form Vista security
Internet Explorer form fill-in setting? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46