簡體   English   中英

UFT不會在Web表格中單擊

[英]UFT does not click in the webtable

我在使用UFT時遇到問題。 我有一個網絡表格。 我記錄了Webtable,然后將Webtable從OR拖到編輯器中。

然后,我進行了如下修改。 單元格1和單元格2返回正確的數據。 在單元內,我只有文本。

cell1 = Browser("Create").Page("Create").WebTable("First").GetCellData(2,1)
print cell1
cell2 = Browser("Create").Page("Create").WebTable("First").GetCellData(3,1)
print cell2

Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "WebElement",0).click

set objLink =Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "WebElement",0)
objLink.Click

set objLink =Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "Link",0)
objLink.Click

它正在查找Web表並返回數據,但未單擊該行。 如何單擊Web表中的第一行?

首先,您需要確保Web表格的cell(2,1)中具有鏈接。 為此,檢查對象的存在:

set objLink =Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "Link",0)
msgbox objLink.Exist(2)

如果返回True ,那么我們將繼續前進。


嘗試在運行時將ReplayType設置更改為2 ,如下所示:

set objLink =Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "Link",0)
setting.webpackage("replayType") = 2      'Runs mouse operations using the mouse. It will move the mouse pointer physically to the position where click will be performed
objLink.highlight
objLink.click
setting.webpackage("replayType") = 1      'Changing back to Event. Runs mouse operations using browser events.

您也可以從此處手動更改replayType設置:工具>選項> Gui測試> Web>高級>運行設置>重放類型


如果這不起作用,則可以在鏈接對象上觸發Click事件 ,如下所示:

set objLink = Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "Link",0)
objLink.highlight
objLink.fireevent "onclick"

即使這不起作用,您也可以嘗試以下方法(盡管不建議這樣做,但是如果我們正確地進行計算,它將可以使用)。 我們嘗試在對象的某個位置找到位置然后在該位置執行MouseClick操作。

set objLink = Browser("Create").Page("Create").WebTable("First").ChildItem(2, 1, "Link",0)
objLink.highlight

Set mobj = CreateObject("Mercury.DeviceReplay")
x = objLink.getRoProperty("abs_x")              'x-axis: Returns the position in pixels from the Top left corner of your monitor screen(not the parent object)
y = objLink.getRoProperty("abs_y")              'y-axis: Returns the position in pixels from the Top left corner of your monitor screen(not the parent object)
h = objLink.getRoProperty("height")             'returns height of the link object in pixels
w = objLink.getRoProperty("width")              'returns width of the link object in pixels

mobj.MouseClick Cint(x+h/4),Cint(y+w/4),1       'Try playing with the denominator 4. If you set it 2, it will attempt to click on the middle of the object.

只需單擊“行”即可獲得TR元素

RowNum=1 'The Row Number you want to click

'if the event handled over TR element then use without Replaytype =2
     Browser("Create").Page("Create").WebTable("First").WebElement("Html tag:=TR","Index:=" & RowNum-1).Click

'otherwise use with ReplayType = 2
     Setting.WebPackage("ReplayType") = 2
     Browser("Create").Page("Create").WebTable("First").WebElement("Html tag:=TR","Index:=" & RowNum-1).Click

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM