# GetElementsByName not setting value

**URL:** <https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195>\
**Category:** PowerShell Help\
**Created:** [May 14, 2015, 12:50am UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195 "2015-05-14T00:50:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph-monarch](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@joseph-monarch](https://forums.powershell.org/u/joseph-monarch)\
**Post date:** [May 14, 2015, 12:50am UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195/1 "2015-05-14T00:50:45Z")

</div>

I am trying to set a value for a web form. I have followed multiple tutorials with no success. I get the following error

```
Exception setting "value": "The property 'value' cannot be found on this object. Verify that the property exists and can be set."
```

Here is my code:

```
$ie = New-Object -Com "InternetExplorer.Application"
$ie.Navigate("https:// ******************* /ccmadmin/showHome.do")
$ie.Visible = $true
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.Document.getElementsByName("j_username").value = "aaaaa"
```

When I get the properties I get the following:

```
className : 
id : 
tagName : INPUT
parentElement : System.__ComObject
style : System.__ComObject
onhelp : 
onclick : 
ondblclick : 
onkeydown : 
onkeyup : 
onkeypress : 
onmouseout : 
onmouseover : 
onmousemove : 
onmousedown : 
onmouseup : 
document : mshtml.HTMLDocumentClass
title : 
language : 
onselectstart : 
sourceIndex : 75
recordNumber : 
lang : 
offsetLeft : 1
offsetTop : 2
offsetWidth : 142
offsetHeight : 19
offsetParent : System.__ComObject
innerHTML : 
innerText : 
outerHTML : 
outerText : 
parentTextEdit : System.__ComObject
isTextEdit : True
filters : System.__ComObject
ondragstart : 
onbeforeupdate : 
onafterupdate : 
onerrorupdate : 
onrowexit : 
onrowenter : 
ondatasetchanged : 
ondataavailable : 
ondatasetcomplete : 
onfilterchange : 
children : System.__ComObject
all : System.__ComObject
scopeName : HTML
onlosecapture : 
onscroll : 
ondrag : 
ondragend : 
ondragenter : 
ondragover : 
ondragleave : 
ondrop : 
onbeforecut : 
oncut : 
onbeforecopy : 
oncopy : 
onbeforepaste : 
onpaste : 
currentStyle : System.__ComObject
onpropertychange : 
tabIndex : 0
accessKey : 
onblur : 
onfocus : 
onresize : 
clientHeight : 17
clientWidth : 140
clientTop : 1
clientLeft : 1
readyState : complete
onreadystatechange : 
onrowsdelete : 
onrowsinserted : 
oncellchange : 
dir : 
scrollHeight : 17
scrollWidth : 140
scrollTop : 0
scrollLeft : 0
oncontextmenu : 
canHaveChildren : False
runtimeStyle : System.__ComObject
behaviorUrns : System.__ComObject
tagUrn : 
onbeforeeditfocus : 
isMultiLine : False
canHaveHTML : False
onlayoutcomplete : 
onpage : 
onbeforedeactivate : 
contentEditable : inherit
isContentEditable : True
hideFocus : False
disabled : False
isDisabled : False
onmove : 
oncontrolselect : 
onresizestart : 
onresizeend : 
onmovestart : 
onmoveend : 
onmouseenter : 
onmouseleave : 
onactivate : 
ondeactivate : 
onmousewheel : 
onbeforeactivate : 
onfocusin : 
onfocusout : 
uniqueNumber : 1
uniqueID : ms__id1
nodeType : 1
parentNode : System.__ComObject
childNodes : System.__ComObject
attributes : System.__ComObject
nodeName : INPUT
nodeValue : 
firstChild : 
lastChild : 
previousSibling : 
nextSibling : 
ownerDocument : mshtml.HTMLDocumentClass
prefix : 
localName : 
namespaceURI : 
textContent : 
dataFld : 
dataSrc : 
dataFormatAs : 
role : 
ariaBusy : 
ariaChecked : 
ariaDisabled : 
ariaExpanded : 
ariaHaspopup : 
ariaHidden : 
ariaInvalid : 
ariaMultiselectable : 
ariaPressed : 
ariaReadonly : 
ariaRequired : 
ariaSecret : 
ariaSelected : 
ie8_attributes : 
ariaValuenow : 
ariaPosinset : 
ariaSetsize : 
ariaLevel : 
ariaValuemin : 
ariaValuemax : 
ariaControls : 
ariaDescribedby : 
ariaFlowto : 
ariaLabelledby : 
ariaActivedescendant : 
ariaOwns : 
ariaLive : 
ariaRelevant : 
ie9_tagName : 
ie9_nodeName : 
onabort : 
oncanplay : 
oncanplaythrough : 
onchange : 
ondurationchange : 
onemptied : 
onended : 
onerror : 
oninput : 
onload : 
onloadeddata : 
onloadedmetadata : 
onloadstart : 
onpause : 
onplay : 
onplaying : 
onprogress : 
onratechange : 
onreset : 
onseeked : 
onseeking : 
onselect : 
onstalled : 
onsubmit : 
onsuspend : 
ontimeupdate : 
onvolumechange : 
onwaiting : 
constructor : 
onmspointerdown : 
onmspointermove : 
onmspointerup : 
onmspointerover : 
onmspointerout : 
onmspointercancel : 
onmspointerhover : 
onmslostpointercapture : 
onmsgotpointercapture : 
onmsgesturestart : 
onmsgesturechange : 
onmsgestureend : 
onmsgesturehold : 
onmsgesturetap : 
onmsgesturedoubletap : 
onmsinertiastart : 
onmstransitionstart : 
onmstransitionend : 
onmsanimationstart : 
onmsanimationend : 
onmsanimationiteration : 
oninvalid : 
xmsAcceleratorKey : 
spellcheck : False
onmsmanipulationstatechanged : 
oncuechange : 
type : text
value : 
name : j_username
status : False
form : System.__ComObject
size : 20
maxLength : 128
defaultValue : 
readOnly : False
indeterminate : False
defaultChecked : False
checked : False
border : 
vspace : 0
hspace : 0
alt : 
src : 
lowsrc : 
vrml : 
dynsrc : 
complete : False
loop : 1
align : 
width : 0
height : 0
start : fileopen
accept : 
useMap : 
selectionStart : 
selectionEnd : 
ie8_src : 
ie8_lowsrc : 
ie8_vrml : 
ie8_dynsrc : 
min : 
max : 
step : 
valueAsNumber :
```

Any thoughts on why I can’t set the value?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 14, 2015, 12:55am UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195/2 "2015-05-14T00:55:36Z")

</div>

It’s probably returning a collection class of some sort, and you want to set the value on an element in that collection. Try this, to be sure:

```
Get-Member -InputObject $ie.Document.getElementsByName("j_username")
```

---

<div class="post-metadata">

**Author:** ![joseph-monarch](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@joseph-monarch](https://forums.powershell.org/u/joseph-monarch)\
**Post date:** [May 14, 2015, 1:00am UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195/3 "2015-05-14T01:00:13Z")

</div>

I get the following:

```
TypeName: System.__ComObject#{3050f56b-98b5-11cf-bb82-00aa00bdce0b}

Name MemberType Definition                          
---- ---------- ----------                          
ie8_item Method IHTMLElement2 ie8_item (int)        
ie8_namedItem Method IHTMLElement2 ie8_namedItem (string)
item Method IDispatch item (Variant, Variant)   
namedItem Method IDispatch namedItem (string)        
tags Method IDispatch tags (Variant)            
toString Method string toString ()                  
urns Method IDispatch urns (Variant)            
constructor Property IDispatch constructor () {get}      
ie8_length Property int ie8_length () {get}             
length Property int length () {get} {set}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 14, 2015, 1:20am UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195/4 "2015-05-14T01:20:19Z")

</div>

Yep, so you probably need to try something like this:

```
$ie.Document.getElementsByName("j_username").ie8_item(0).value = "aaaaa"
```

---

<div class="post-metadata">

**Author:** ![joseph-monarch](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@joseph-monarch](https://forums.powershell.org/u/joseph-monarch)\
**Post date:** [May 14, 2015, 1:30am UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195/5 "2015-05-14T01:30:13Z")

</div>

Error

```
Exception setting "value": "Cannot set the Value property for PSMemberInfo object of type "System.Management.Automation.PSMethod"."
```

Would there be an easy way to find the index or do I just need to keep trying numbers.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/getelementsbyname-not-setting-value/4195/6 "2024-05-16T20:46:13Z")

</div>


