Search code examples
qtphp-uft

UFT does not click in the webtable


I am having an issue with UFT. I have a webtable. I recorded the webtable and then dragged the webtable from OR to the editor.

Then I modified as following. Cell 1 and Cell 2 return the correct data. 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. How can I click the First row in the webtable?


Solution

  • Firstly, you need to be sure that the cell(2,1) of the webtable has a link in it. 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.


    Try changing the ReplayType setting to 2 during the runtime as below:

    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


    If that doesn't work, you can fire the Click Event on the Link object as shown below:

    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.

    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.