javascript - Property 'value' cannot be found on this object in Powershell - Stack Overflow

I have following HTML for 'User Name' which I would like to set in my script.<input id=&qu

I have following HTML for 'User Name' which I would like to set in my script.

<input id="user_name" value="" autoplete="off" type="text" name="user_name">

Here is the powershell code I have written to achieve it :

$ie = new-object - InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate(".do")

while ($ie.Busy) {start-sleep -s 3}

$ie.Document.getElementByID("user_name").value = "Username"
$ie.Document.getElementByID("user_password").value = "Password"

This is the Error I receive :

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At D:\servicenow.ps1:7 char:1
+ $ie.Document.getElementByID("user_name").value = "Username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

I have following HTML for 'User Name' which I would like to set in my script.

<input id="user_name" value="" autoplete="off" type="text" name="user_name">

Here is the powershell code I have written to achieve it :

$ie = new-object - InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate("https://abcdnow./navpage.do")

while ($ie.Busy) {start-sleep -s 3}

$ie.Document.getElementByID("user_name").value = "Username"
$ie.Document.getElementByID("user_password").value = "Password"

This is the Error I receive :

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At D:\servicenow.ps1:7 char:1
+ $ie.Document.getElementByID("user_name").value = "Username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
Share Improve this question asked Feb 18, 2015 at 10:52 PowershelPowershel 6354 gold badges11 silver badges18 bronze badges 1
  • Have you verified if this element exists? Because your code works for me with another address and element. – wallybh Commented Feb 18, 2015 at 11:00
Add a ment  | 

1 Answer 1

Reset to default 1

It's because your controls are inside a frame. You have to do this:

$ie.Document.getElementById("gsft_main").contentWindow.document.getElementByID("user_name").value = "UserName"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745110924a4611846.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信