簡體   English   中英

在QTP中標識WebTable / WebGrid對象

[英]Identifying an WebTable/WebGrid Object in QTP

我在WebTable(Web Grid)的html中有以下代碼。

<table width="90%">
  <div class="greybox" style="margin-top:2%;">
    <table class="datagrid" width ="100%">....<table>
  </div>
</table>

我嘗試在描述性編程中提供完全相同的(所有)屬性,但是QTP不能識別Web元素(DIV)。 有沒有一種獨特的方式來識別這一點?

注意:網頁是開發為單頁應用程序

編輯:

所以我想我已經用下面的代碼解決了這個問題。 有兩個沒有“唯一文本” if子句的對象。 第一個對象是DIV對象的父對象,因此必須使用第一個對象中的“唯一文本”,該文本不會成為任何其他對象的一部分。 我目前正在嘗試使用其他數據,以查看是否工作正常

Browsername = Browser("micClass:=Browser").GetROProperty("name")
Pagename = Browser("micClass:=Browser").Page("micClass:=Page").GetROProperty("name")

Set desc = Description.Create()
desc("micclass").Value = "Webelement"

Set ChildObject=Browser("name:="&BrowserName).Page("name:="&PageName).ChildObjects(desc)

Set Child_Table_Value = nothing

For i=0 to ChildObject.Count-1
  innerhtmlvalue = ChildObject(i).GetRoproperty("innerhtml")
  htmltag = ChildObject(i).GetRoproperty("micclass")

  if(Instr(innerhtmlvalue, "MARGIN-TOP: 2%")<>0) then 
    if(Instr(innerhtmlvalue, "UniqueText")=0) then
      if(Instr(htmltag, "WebElement")<>0) then
        Set Child_Table_Value  = ChildObject(i)
      End If
    End If
  End IF
Next

Set Table_Value = Child_Table_Value.WebTable("html tag:=Table")

好的,假設您具有這樣的HTML結構:

<table width="90%">
  <tr>
    <td>
      <div class="greybox" style="margin-top:2%;">
        <table class="datagrid" width="100%">
          <tr>
            <td>UniqueText</td>
          </tr>
        </table>
      </div>
    </td>
  </tr>
</table>

...並且根據您當前的解決方案,您可以依靠存在的“ UniqueText”,然后可以嘗試以下XPath語句:

(//table[contains(., 'UniqueText')])[last()]

因此,在QTP / UFT中,您將執行以下操作:

Browser("micClass:=Browser").Page("micClass:=Page").WebTable("xpath:=(//table[contains(., 'UniqueText')])[last()]")

嘗試如下使用。(嘗試使用“類”標識div塊)

Browser("micClass:=Browser").Page("micClass:=Page").Webelement("class:=greybox").Webtable("class:=datagrid")

請告訴我

暫無
暫無

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

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