简体   繁体   English

UFT不会在Web表格中单击

[英]UFT does not click in the webtable

I am having an issue with UFT. 我在使用UFT时遇到问题。 I have a webtable. 我有一个网络表格。 I recorded the webtable and then dragged the webtable from OR to the editor. 我记录了Webtable,然后将Webtable从OR拖到编辑器中。

Then I modified as following. 然后,我进行了如下修改。 Cell 1 and Cell 2 return the correct data. 单元格1和单元格2返回正确的数据。 Inside the cells, I have only texts. 在单元内,我只有文本。

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

It is finding the webtable and returning the data but not clicking the row. 它正在查找Web表并返回数据,但未单击该行。 How can I click the First row in the webtable? 如何单击Web表中的第一行?

Firstly, you need to be sure that the cell(2,1) of the webtable has a link in it. 首先,您需要确保Web表格的cell(2,1)中具有链接。 For that, check for the object's existence: 为此,检查对象的存在:

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

If it returns True , then we are good to move ahead. 如果返回True ,那么我们将继续前进。


Try changing the ReplayType setting to 2 during the runtime as below: 尝试在运行时将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.

You can also manually change the replayType Setting from here: Tools > Options > Gui Testing > Web > Advanced > Run Settings > Replay Type 您也可以从此处手动更改replayType设置:工具>选项> Gui测试> Web>高级>运行设置>重放类型


If that doesn't work, you can fire the Click Event on the Link object as shown below: 如果这不起作用,则可以在链接对象上触发Click事件 ,如下所示:

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

Even if that doesn't work, you can try the following method(not recommended though, but if we do the calculations correctly, it will work). 即使这不起作用,您也可以尝试以下方法(尽管不建议这样做,但是如果我们正确地进行计算,它将可以使用)。 We try to find the position somewhere on the object and perform the MouseClick operation at that position. 我们尝试在对象的某个位置找到位置然后在该位置执行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.

Just click Row by getting TR element 只需单击“行”即可获得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