【问题标题】:Powershell Internet Explorer AutomationPowershell Internet Explorer 自动化
【发布时间】:2018-12-18 18:20:27
【问题描述】:

尝试让 powershell 每隔一段时间启动不同的网站。

这是一个有效的脚本:

function IEWeb {

    $ie = New-Object -Comobject 'InternetExplorer.Application'
    $ie.visible=$true

    Do
    {
        $ie.navigate('http://p-captas02.int.addom.dk/cap-tas-views/Queue.aspx')
        start-sleep 15

        $ie.navigate('https://oneview.int.addom.dk/dashboard?dashboard_id=1')
        start-sleep 15

        $ie.navigate('https://oneview.int.addom.dk/dashboard?time=0&scroll_value=15&dashboard_id=10')
        start-sleep 15
    } 

    While ($ie.name -contains 'Internet Explorer') 

}#Function

问题是不是每次都有效

有谁知道另一种方法吗?

网站在同一个标​​签页中启动很重要

【问题讨论】:

  • 你说的“不是每次都有效”是什么意思?你的意思是它不打开 IE,不加载 next 页面,跳过页面等等?您需要在代码中添加一些调试消息,例如Write-Output "started do loop"
  • IE,不加载下一页,它只是停止,然后不再发生

标签: powershell internet-explorer


【解决方案1】:

我认为在尝试导航到下一个 url 之前,最好检查一下用户是否没有关闭 IE。另外,$ie.name 是一个字符串,所以$ie.name -contains 'Internet Explorer' 是错误的。

也许这对你更有效。

function IEWeb {
    # create an array with the urls you want to revolve
    $urls = 'http://p-captas02.int.addom.dk/cap-tas-views/Queue.aspx',
            'https://oneview.int.addom.dk/dashboard?dashboard_id=1',
            'https://oneview.int.addom.dk/dashboard?time=0&scroll_value=15&dashboard_id=10'

    $ie = New-Object -Comobject 'InternetExplorer.Application'
    $ie.visible=$true

    $index = 0
    while ($ie.HWND) {   # for as long as the user does not close IE
        $ie.navigate($urls[$index])
        Start-Sleep 15
        # increment the array counter, and revert to index 0 if $urls length is reached
        $index = ($index + 1) % $urls.Count
    } 

    try {
        # close and release the Com object from memory
        $ie.Quit()
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ie) | Out-Null
        [System.GC]::Collect()
        [System.GC]::WaitForPendingFinalizers()
    }
    catch {}
}

IEWeb

【讨论】:

  • 非常感谢,我会尽快试用的!
猜你喜欢
  • 1970-01-01
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 2018-12-18
  • 2010-10-16
  • 2020-07-11
  • 2012-02-20
相关资源
最近更新 更多