Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a solution that uses the <code>sourceIndex</code> attribute, note that <code>sourceIndex</code> is an IE only property but QTP simulates it on Firefox so the same script will work on both browsers. You can choose to use coordinate based properties like <code>abs_x</code> and <code>abs_y</code> if <code>source_index</code> doesn't fit the bill.</p> <p>The code that follows answers the question as asked, making it into a general function is left as an exercise for the reader ;o)</p> <pre><code>''#1. Create description for locator text Set textD = Description.Create() textD("micclass").Value = "WebElement" textD("innertext").Value = ".*Item XYZ-123.*" ''#2. Find locator sourceIndex set texts = Browser("B").Page("P").ChildObjects(textD) Set text = texts(texts.Count-1) ' Take last text ' textIdx = text.GetROProperty("source_index") ' works for FF too ' ''#3. Create description for button Set buttonD = Description.Create() buttonD("micclass").Value = "WebButton" buttonD("value").Value = "Delete" Set btns = Browser("B").Page("P").ChildObjects(buttonD) ''#4. Find first button after locator text For i = 0 To btns.Count If btns(i).GetROProperty("source_index") &gt; textIdx Then btns(i).Click ' Or whatever you want to do with it ' Exit For End If Next </code></pre> <p><strong>Things to note about this solution:</strong></p> <ul> <li>It doesn't assume anything about the element containing the text, if you know that this is the entire text in the element you can remove the <code>.*</code>s and/or add an "html tag" for much better performance. <ul> <li>That's why we take the last element that fits the description, the first element will be the <code>BODY</code> etc.</li> </ul></li> <li>In the text's description we have to specify "micclass" = "WebElement" because by default <code>ChildObject</code> filters out <code>WebElement</code>s assuming that they are un-interesting.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload