I want to create a script with PowerShell to check the flight status. But it´s not possible for me to set textbox value.
How can I fix it? Thank you in advance!
Error: Property 'value' cannot be found on this object; make sure it exists and is settable.
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
Try this:
$ie.document.getElementByID("ns_7_CO19VHUC6FFPF0I5O4OBCT2OE4_flightNumber").value = $flightNumber
This works for me. I found the ID by looking at the source code through my browser.
I don't know why getElementsByName doesn't work. Perhaps someone else can shed some light on this?
Edit:
Okay, I figured it out. getElementsByName returns a collection. You have to iterate through the collection to set the value. So your code would 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
}
This worked for me.
Very simple , just look for 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With