PowerShell: write value in input form = file.

I have input type = text input fields on a web page. I load and fill in the values ​​and click the submit button, which works fine:

$ie=New-Object -comobject InternetExplorer.Application 
$ie.visible=$true 
$ie.Navigate("https://myurl/test.html") 
while($ie.busy){Start-Sleep 1} 
$ie.Document.getElementById("field_firstName").value="Firstname" 
$ie.Document.getElementById("field_lastName").value="Lastname" 
$ie.Document.getElementById("btn_upload").Click() 
while($ie.busy){Start-Sleep 1}

I would also like to populate the input type = file field with c: \ temp \ test.txt and load it. I read that for security reasons value = is not supported in browsers.

Is there a way around the solution with PowerShell? Maybe click the browse button and select a file or use sendkeys?

+5
source share
3 answers

Jaykul post. Watin . . , :

$WatinPath = 'c:\bin\watin\WatiN.Core.dll' #path with downloaded assembly
$watin     = [Reflection.Assembly]::LoadFrom( $WatinPath )

$ie        = new-object WatiN.Core.IE("https://myurl/test.html")
$file1 = $ie.FileUpload('file1') #id of the input
$file1.set('C:\temp\test.txt') # path to the file

# and now just find the button and click on it
$o = $ie.Button('send') #send is id of the submit button
$o.Click()

IE WebClient , , , .

Edit:

, ,

$f = $ie.FileUpload({param($fu) $fu.GetAttributeValue("name") -eq 'the name you have' })

$f = $ie.FileUploads | ? { $_.GetAttributeValue("name") -eq 'the name you have' }
+4

WebClient HttpWebRequest , IE GUI. WebClient PowerShell.

+1

, SendKeys, IE. IE8 .

0

All Articles