Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用powershell登录到网站_Powershell_Testing_Automation_Internet Explorer 11_Webautomation - Fatal编程技术网

无法使用powershell登录到网站

无法使用powershell登录到网站,powershell,testing,automation,internet-explorer-11,webautomation,Powershell,Testing,Automation,Internet Explorer 11,Webautomation,我正在尝试使用下面的代码登录到一个站点 $IE = New-Object -ComObject InternetExplorer.Application $Url = "https://example.com" $IE.Navigate($Url) $IE.Visible = $true while ($IE.busy) { start-sleep -milliseconds 1000 } $elements = $IE.Document.getElementById("

我正在尝试使用下面的代码登录到一个站点

$IE = New-Object -ComObject InternetExplorer.Application

$Url = "https://example.com"

$IE.Navigate($Url)

$IE.Visible = $true

 while ($IE.busy) {
 start-sleep -milliseconds 1000 
 } 



$elements = $IE.Document.getElementById("userID")

Foreach($element in $elements)
    {
        $element.value = "user"
    } 


$elements = $IE.Document.getElementById("pswd")

Foreach($element in $elements)
    {
        $element.value = "password"
    } 


$elements = $IE.Document.getElementByName("configCombo")

Foreach($element in $elements)
    {
        $element.value = "config"
    } 
但除了导航到url外,似乎没有发生任何其他情况。用户名、密码和配置字段中的值没有被代码填充。在堆栈溢出中查找了此类情况,但找不到任何情况。因此,将此作为一个新问题发布

我已取消选中IE中的启用保护模式


如果您有任何想法/解决方案,我们将不胜感激。

在运行时,我也不会遇到任何错误。首先,元素不是数组。它是单个元素,因此不需要Foreach。你应该删除those@ArcSet2如果删除foreach,则会出现错误“在该对象上找不到属性‘value’。请验证该属性是否存在并可以设置”。这是因为该对象为空,而不是因为它是arrayI的Get成员,并且它返回了它具有‘value’属性。technet的一篇文章中建议使用foreach循环。technet文章中给出的理由是,可能有多个元素具有相同的ID。