PowerShell - IE object, error setting value

I want to create a script using PowerShell to check flight status. But I can not set the value of the text field.

How can i fix this? Thank you in advance!

Error: the 'value' property could not be found on this object; make sure it exists and is accessible.

the code:

#Flight Number (Only Lufthansa) #For example flight number [string]$flightNumber = "LH 3102" $ie = new-object -com "InternetExplorer.Application" $ie.navigate("http://www.lufthansa.com/de/de/Ankunft-und-Abflug") $ie.visible = $true sleep 5 #while ($ie.busy) {sleep -milliseconds 50} while($ie.ReadyState -ne 4) {start-sleep -m 100} $ie.document.getElementsByName("flightNumber").value = $flightNumber #Error $ie.document.getElementsByName("flightNumber").IHTMLInputTextElement_value = $flightNumber #Error $ie.document.getElementsByName("flightNumber").IHTMLInputElement_value = $flightNumber #Error 
+6
source share
2 answers

Try the following:

 $ie.document.getElementByID("ns_7_CO19VHUC6FFPF0I5O4OBCT2OE4_flightNumber").value = $flightNumber 

This works for me. I found the identifier by looking at the source code through my browser.

I do not know why getElementsByName does not work. Perhaps someone else can shed light on this?


Edit:

Ok, I figured it out. getElementsByName returns the collection. You must iterate through the collection to set the value. So your code will look like this:

 #Flight Number (Only Lufthansa) #For example flight number [string]$flightNumber = "LH 3102" $ie = new-object -com "InternetExplorer.Application" $ie.navigate("http://www.lufthansa.com/de/de/Ankunft-und-Abflug") $ie.visible = $true sleep 5 #while ($ie.busy) {sleep -milliseconds 50} while($ie.ReadyState -ne 4) {start-sleep -m 100} $elements = $ie.document.getElementsByName("flightNumber") Foreach($element in $elements) { $element.value = $flightnumber } 

It worked for me.

+5
source

Very simple, just find the tag name:

 $ie = New-Object -com InternetExplorer.Application $ie.visible=$true $ie.navigate("http://www.lufthansa.com/de/de/Ankunft-und-Abflug") while($ie.ReadyState -ne 4) {start-sleep -m 100} # here is where the magic happens $termsField = $ie.document.getElementsByName("routeDepartureStationName") @($termsField)[0].value ="powershell" 

enter image description here

+1
source

Source: https://habr.com/ru/post/907111/


All Articles