user3290171 user3290171 - 1 year ago 226
HTML Question

Powershell - Get value of text box on web page and save as txt file

I am currently scripting something that will go to a certain web page. Once on the web page it will click the run button which will calculate a value on the webpage and put it in a read only text area with the id="result Console". The code that does this is below:

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true

while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}

$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.className -eq "runButton"}


After it does the above I need to get the text that is in the text area and save it to a txt file.

I was wondering if this was possible and if so how I would go about doing so?

I presume I could get the text from the text area in to a variable and then export this using the below command:

$example | out-file -filepath C:\temp\example.txt

I would appreciate any help you can give on this.

Thanks in advance,


Answer Source

If the textarea has an id value set, I guess you can use the getElementById with the id as parameter:

$example = $ie.Document.getElementById("id of the textarea")

$example.value #should have the text you want to write to the txt file

It's been a while I wrote Powershell script but I remember doing it this way last time I needed the text from a textarea.

Hope this helps, good luck.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download