Need help in updating a filed value in Powershell

This topic contains 8 replies, has 2 voices, and was last updated by  Max Kozlov 5 months, 2 weeks ago.

  • Author
    Posts
  • #72031

    Naveenkumar K
    Participant

    Hi All,

    I have written the below code to update the search vlaue to "X"

    while ($ie.Busy -eq $true){Start-Sleep -seconds 4;}
    $field1= $ie.document.getElementByID('C0_54')
    $field1.value="X"
    

    But getting below error

    Property 'value' cannot be found on this object; make sure it exists and is settable.
    At line:51 char:9
    + $field1. <<<< value="X" + CategoryInfo : InvalidOperation: (value:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Thanks

  • #72038

    Max Kozlov
    Participant

    make some tests

    $field1 -eq $null
    Get-Member -InputObject $field1
    
  • #72043

    Naveenkumar K
    Participant

    Here is the output of GET-MEMBER

    True
    
    
       TypeName: System.String
    
    Name             MemberType            Definition                                                                          
    ----             ----------            ----------                                                                          
    Clone            Method                System.Object Clone()                                                               
    CompareTo        Method                int CompareTo(System.Object value), int CompareTo(string strB)                      
    Contains         Method                bool Contains(string value)                                                         
    CopyTo           Method                System.Void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int...
    EndsWith         Method                bool EndsWith(string value), bool EndsWith(string value, System.StringComparison ...
    Equals           Method                bool Equals(System.Object obj), bool Equals(string value), bool Equals(string val...
    GetEnumerator    Method                System.CharEnumerator GetEnumerator()                                               
    GetHashCode      Method                int GetHashCode()                                                                   
    GetType          Method                type GetType()                                                                      
    GetTypeCode      Method                System.TypeCode GetTypeCode()                                                       
    IndexOf          Method                int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf(cha...
    IndexOfAny       Method                int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), int I...
    Insert           Method                string Insert(int startIndex, string value)                                         
    IsNormalized     Method                bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normalizatio...
    LastIndexOf      Method                int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int Las...
    LastIndexOfAny   Method                int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startIndex...
    Normalize        Method                string Normalize(), string Normalize(System.Text.NormalizationForm normalizationF...
    PadLeft          Method                string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)    
    PadRight         Method                string PadRight(int totalWidth), string PadRight(int totalWidth, char paddingChar)  
    Remove           Method                string Remove(int startIndex, int count), string Remove(int startIndex)             
    Replace          Method                string Replace(char oldChar, char newChar), string Replace(string oldValue, strin...
    Split            Method                string[] Split(Params char[] separator), string[] Split(char[] separator, int cou...
    StartsWith       Method                bool StartsWith(string value), bool StartsWith(string value, System.StringCompari...
    Substring        Method                string Substring(int startIndex), string Substring(int startIndex, int length)      
    ToCharArray      Method                char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)                
    ToLower          Method                string ToLower(), string ToLower(System.Globalization.CultureInfo culture)          
    ToLowerInvariant Method                string ToLowerInvariant()                                                           
    ToString         Method                string ToString(), string ToString(System.IFormatProvider provider)                 
    ToUpper          Method                string ToUpper(), string ToUpper(System.Globalization.CultureInfo culture)          
    ToUpperInvariant Method                string ToUpperInvariant()                                                           
    Trim             Method                string Trim(Params char[] trimChars), string Trim()                                 
    TrimEnd          Method                string TrimEnd(Params char[] trimChars)                                             
    TrimStart        Method                string TrimStart(Params char[] trimChars)                                           
    Chars            ParameterizedProperty char Chars(int index) {get;}                                                        
    Length           Property              System.Int32 Length {get;}                                                          
    Property 'value' cannot be found on this object; make sure it exists and is settable.
    At line:54 char:9
    + $field1. < <<< value="X"
    
  • #72046

    Naveenkumar K
    Participant

    My URL source for this value:

    input name="0_54" tabindex="4" title="Search Type" class="textfield" id="C0_54" style="width: 32px; vertical-align: top; cursor: auto;" onmouseover="updateHelpCursor('',this)" onmousedown="FCHandler.onKeyDownTextField(this,'','3', event)" onkeydown="FCHandler.onKeyDownTextField(this,'','3', event,false,'UTC')" onkeyup="FCHandler.onKeyUpTextField(this,'', event)" onhelp="hp('0_54')" onfocus="FCHandler.onFocusVA(this,'',false)" onblur="FCHandler.onExitVA(this,false,'',false)" type="text" maxlength="3" value="*" autocomplete="OFF" htmlpostflag="false" isdropdown="1" hotkey="0" mincharnumber="1" autosuggestenabled="1"
    
  • #72086

    Max Kozlov
    Participant

    you have error somewhere
    both tests can't be -eq $null = 'True' and TypeName: System.String at the same time

    here is the test for this page:

    PS C:\> $ie = New-Object -ComObject InternetExplorer.Application
    PS C:\> $ie.visible=$true
    PS C:\> $url = 'https://powershell.org/forums/topic/need-help-in-updating-a-filed-value-in-powershell/'
    PS C:\> $ie.Navigate($url)
    PS C:\> $element = $ie.Document.getElementById('bbp_topic_tags')
    PS C:\> $element.value
    test
    PS C:\> $element.value = 'test1'
    PS C:\> $element.value
    test1
    
  • #72088

    Naveenkumar K
    Participant

    Ok, tried with name (0_54) instead of ID(C0_054)
    Below is the output

    $field1= $ie.Document.getelementbyid('0_54')
    $field1 -eq "null"
    Get-Member -InputObject "$field1"
    $field1.value="E"

    False
    
    
       TypeName: System.String
    
    Name             MemberType            Definition                                                                                                                                                             
    ----             ----------            ----------                                                                                                                                                             
    Clone            Method                System.Object Clone()                                                                                                                                                  
    CompareTo        Method                int CompareTo(System.Object value), int CompareTo(string strB)                                                                                                         
    Contains         Method                bool Contains(string value)                                                                                                                                            
    CopyTo           Method                System.Void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)                                                                               
    EndsWith         Method                bool EndsWith(string value), bool EndsWith(string value, System.StringComparison comparisonType), bool EndsWith(string value, bool ignoreCase, System.Globalization....
    Equals           Method                bool Equals(System.Object obj), bool Equals(string value), bool Equals(string value, System.StringComparison comparisonType)                                           
    GetEnumerator    Method                System.CharEnumerator GetEnumerator()                                                                                                                                  
    GetHashCode      Method                int GetHashCode()                                                                                                                                                      
    GetType          Method                type GetType()                                                                                                                                                         
    GetTypeCode      Method                System.TypeCode GetTypeCode()                                                                                                                                          
    IndexOf          Method                int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf(char value, int startIndex, int count), int IndexOf(string value), int IndexOf(string ...
    IndexOfAny       Method                int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), int IndexOfAny(char[] anyOf, int startIndex, int count)                                    
    Insert           Method                string Insert(int startIndex, string value)                                                                                                                            
    IsNormalized     Method                bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normalizationForm)                                                                                
    LastIndexOf      Method                int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int LastIndexOf(char value, int startIndex, int count), int LastIndexOf(string value), int...
    LastIndexOfAny   Method                int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startIndex), int LastIndexOfAny(char[] anyOf, int startIndex, int count)                        
    Normalize        Method                string Normalize(), string Normalize(System.Text.NormalizationForm normalizationForm)                                                                                  
    PadLeft          Method                string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)                                                                                       
    PadRight         Method                string PadRight(int totalWidth), string PadRight(int totalWidth, char paddingChar)                                                                                     
    Remove           Method                string Remove(int startIndex, int count), string Remove(int startIndex)                                                                                                
    Replace          Method                string Replace(char oldChar, char newChar), string Replace(string oldValue, string newValue)                                                                           
    Split            Method                string[] Split(Params char[] separator), string[] Split(char[] separator, int count), string[] Split(char[] separator, System.StringSplitOptions options), string[] ...
    StartsWith       Method                bool StartsWith(string value), bool StartsWith(string value, System.StringComparison comparisonType), bool StartsWith(string value, bool ignoreCase, System.Globaliz...
    Substring        Method                string Substring(int startIndex), string Substring(int startIndex, int length)                                                                                         
    ToCharArray      Method                char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)                                                                                                   
    ToLower          Method                string ToLower(), string ToLower(System.Globalization.CultureInfo culture)                                                                                             
    ToLowerInvariant Method                string ToLowerInvariant()                                                                                                                                              
    ToString         Method                string ToString(), string ToString(System.IFormatProvider provider)                                                                                                    
    ToUpper          Method                string ToUpper(), string ToUpper(System.Globalization.CultureInfo culture)                                                                                             
    ToUpperInvariant Method                string ToUpperInvariant()                                                                                                                                              
    Trim             Method                string Trim(Params char[] trimChars), string Trim()                                                                                                                    
    TrimEnd          Method                string TrimEnd(Params char[] trimChars)                                                                                                                                
    TrimStart        Method                string TrimStart(Params char[] trimChars)                                                                                                                              
    Chars            ParameterizedProperty char Chars(int index) {get;}                                                                                                                                           
    Length           Property              System.Int32 Length {get;}                                                                                                                                             
    Property 'value' cannot be found on this object; make sure it exists and is settable.
    At line:62 char:9
    + $field1. < <<< value="E"
        + CategoryInfo          : InvalidOperation: (value:String) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound
    
    

    Any suggestions?

  • #72161

    Max Kozlov
    Participant

    if you use name, you should use getElementsByName()

    but now I see your error, WTH you write
    Get-Member -InputObject "$field1"
    instead of
    Get-Member -InputObject $field1
    ?
    I did not ask you to use quotes!
    and in addition test you data with
    $field1 | fl *

  • #72260

    Naveenkumar K
    Participant

    Tried with your suggestion and below is the output

    $field1= $ie.Document.getelementbyid('0_54')
    $field1 -eq "null"
    Get-Member -InputObject $field1
    $field1 | fl *

    —–
    False

    System.__ComObject

    Thanks

  • #72304

    Max Kozlov
    Participant

    be More attentive
    -eq 'null' should be -eq $null
    and so on
    'System.__ComObject' still looks like quoted object (so it converted to string instead of displaying it properties)

    remove ANY possible quote from all of your code
    except quotes inside this parentesis: $ie.Document.getelementbyid('0_54')

    repeat this until you get from $field1 | fl *
    something like this:

    Script                            : System.__ComObject
    all                               : System.__ComObject
    body                              : System.__ComObject
    activeElement                     : System.__ComObject
    images                            : System.__ComObject
    applets                           : System.__ComObject
    links                             : System.__ComObject
    forms                             : System.__ComObject
    anchors                           : System.__ComObject
    title                             : Topic: Need help in updating a filed value in Powershell
    scripts                           : System.__ComObject
    designMode                        : Inherit
    selection                         : System.__ComObject
    readyState                        : complete
    frames                            : System.__ComObject
    embeds                            : System.__ComObject
    plugins                           : System.__ComObject
    alinkColor                        : #0000ff
    .....
    

You must be logged in to reply to this topic.