Forum Discussion

kaiiii's avatar
kaiiii
Regular Contributor
7 years ago
Solved

Click a variable

How can i Click a variable, suppose
Dim b

b = "Hi How are you"

 

 

Now this string is shown on a page....how can i make an object for it so i can use click method

  • Also, if you want to specifically use the variable, and don't mind using xpath, you can do the following:

     

    dim b, obj, xpath
    
    b = "Hi How are you"
    xpath = "//*[text()='" & b & "']"
    Set page = Sys.Browser("*").Page("*")
    Set obj = page.FindChildByXPath(xpath)

    If the variable sting is not unique and there is more than one element in your page with the string, you will have to modify the xpath to get the desired object.

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    OK... have you tried recording what you want to accomplish?  That is always a good way to figure out how TestComplete interacts with your application after which you can make whatever modifications you want.

     

    In this case... there's text on a web page... that text is inside of some web object (TextNode, Panel, Link, etc).  You need to find the pathing to that object (in TestComplete that can be found in the Object Browser and, most likely, in the NameMapping that your record generated).  You then do the following:

     

    //with Name Mapping
    
    Aliases.browser.pageMyPage.panal0.panal1.TextNode0.Click()
    
  • Also, if you want to specifically use the variable, and don't mind using xpath, you can do the following:

     

    dim b, obj, xpath
    
    b = "Hi How are you"
    xpath = "//*[text()='" & b & "']"
    Set page = Sys.Browser("*").Page("*")
    Set obj = page.FindChildByXPath(xpath)

    If the variable sting is not unique and there is more than one element in your page with the string, you will have to modify the xpath to get the desired object.