首页 > 解决方案 > 如何使用 Windows Powershell 在网页中访问基于 javascript 的对话框窗口?

问题描述

我正在访问一个旧的网页,脚本很糟糕,元素识别很差。到目前为止,我可以访问它给我的所有对象。但现在,我被困住了。

当我单击此按钮时,它会打开一个 JavaScript 对话框,用户必须在其中插入一些值。我只是点击它。但是当窗口打开时,我无法专注于它。

这是创建它的代码:

<INPUT onclick="javascript: openCosts(document.forms[0], 'COMPANY');" 
title="Include values" 
style="BORDER-LEFT-WIDTH: 1px; CURSOR: hand; FONT-SIZE: 11px; FONT-FAMILY: Tahoma; BORDER-RIGHT-WIDTH: 1px; 
BORDER-TOP-COLOR: #007041; BORDER-BOTTOM-WIDTH: 1px; BORDER-LEFT-COLOR: #007041; FONT-WEIGHT: bold; 
COLOR: #fff; PADDING-BOTTOM: 1px; BORDER-BOTTOM-COLOR: #007041; PADDING-TOP: 1px; PADDING-LEFT: 3px; 
BORDER-RIGHT-COLOR: #007041; PADDING-RIGHT: 3px; BORDER-TOP-WIDTH: 1px; BACKGROUND-COLOR: #0080ff" 
type=button value="Costs - SAP" name=btn_show_costs></INPUT>

我试图发送 TABS 和 ENTERS;试图让所有打开的 IExplorer 打开窗口 -- $shell = New-Object -ComObject Shell.Application 和 Get-Process | Where-Object ... 不起作用。

有人可以帮我吗??

那是恢复的代码,直到现在......

$ie= new-object -ComObject "InternetExplorer.Application"
$ie.visible=$true
$ie.Navigate("an_local_asp_web_page.asp")

while($ie.ReadyState -ne 4) {start-sleep -m 100}

$ie.Document.getElementById("frame_principal").contentDocument.getElementById("cbb_profile")[2].selected = $true
$ie.Document.getElementById("frame_principal").contentDocument.getElementsByTagName("IMG")[1].click()

start-sleep -m 2000

$image = $ie.Document.getElementById("frame_principal").contentDocument.getElementsByTagName("IMG") | Where-Object { $_.href -like "*img_menu.gif*" }
$image.click() 

start-sleep -m 2000

$ie.Document.getElementById("frame_principal").contentDocument.getElementById("menu_vehicle").contentDocument.getElementsByTagName("IMG")[0].click()

start-sleep -m 1000

$ie.Document.getElementById("frame_principal").contentDocument.getElementById("frame_body").contentDocument.getElementsByName(“txt_user”)[0].value = "NICHOLAS"
$ie.Document.getElementById("frame_principal").contentDocument.getElementById("frame_body").contentDocument.getElementsByName(“rd_driver”)[0].Click()
$ie.Document.getElementById("frame_principal").contentDocument.getElementById("frame_body").contentDocument.getElementsByName(“btn_show_costs”)[0].Click() 

start-sleep -m 1000

# Now, that next part should work... But it doen't. It says 
# 'You cannot call a method on a null-valued expression.'
# I only see the IE Window that generates the Dialog Window... 
$app = New-Object -ComObject Shell.Application
$app.Windows()
$window = $app.Windows() | where {$_.LocationName -like "*show costs*"} 
$image = $window.Document.getElementsByTagName("IMG") | Where-Object { $_.href -like "*bt_add_cost.gif*" }
$image.click()

start-sleep -m 1000

$window.Document.getElementById("rate_cd_cbi").Value = "COSTCENTER"
$window.Document.getElementById("rate").Value = "100"
$window.Document.getElementById("btn_include").Click()

先感谢您!

标签: htmlpowershellwebautomationautomated-tests

解决方案


推荐阅读