Button success

Button success

You're on your way to becoming an Automation Testing machine!

  • aoreta

    Hi,

    I am trying to use DP in doing these exercises and I am having problems when I am trying to use micclass property for the Browser and Page but all is well if I use the title properties for both the Browser and Page.

    My code is like this:
    Browser(“micclass:=Browser”).Page(“micclass:=Page”).WebButton(“html id:=idExample”).Click

    Error returned is:
    Cannot find the “[ WebButton ]” object’s parent “[ Browser ]” (class Browser). Verify that parent properties match an object currently displayed in your application.

    Am I missing something here? I tried to look it up but found no indicators that the above line is incorrect.

    Adrian

    • QTPtutorialnet

      Hi. Your browser and page sent unique objects. Make the browser “index:=0” and make sure it’s the only browser window open. Then make the page “title:=.*” try that and let me know if it works.

      • QTPtutorialnet

        Browser(“index:=0”).Page(“title:=.*)

        • aoreta

          Thanks a lot. Your input also made it work. With the index:=0, even if I have more than 1 tab opened, it will still access the 1st tab

  • aoreta

    Hi,

    I have another question, but this is related to the Advance Controls practice example, specifically for the toggling tab. Based on the behavior, the text output would depend on the selected link, which in this case either “Tab 1” or “Tab 2”.

    I was able to control the selection of the links using the code:
    Browser(“index:=0”).Page(“title:=.*”).Link(“name:=Tab 1”).Click
    ***I can change the selection fom Tab 1 to Tab 2 just by changing the name property in the Link

    Now, what I want to do is to do a checking on the output text. So if Tab 1 is selected, I would want to check that the text output is “This is tab 1” and if Tab 2 is selected it should show “This is tab 2”. I’ve been trying to get QTP to recognize the WebElement but am confused as I was able to see that there are two WebElements related to it. How do you do a checking in this case and how do you successfully recognize the correct object for the text?

    • QTPtutorialnet

      You can simply switch tabs by changing the browser index. So tab 1 index:=0, tab 2 index:=1, and so on. If you want to verify which tab or page you’re on, you can do this: ex. Browser(“Index:=0”) or Browser(“Index:=0”)

      strPagerName = Browser(“Index:=1”).Page(“Index:=0”).GetROProperty(“title”)

      MsgBox strPagerName

      This will print the name of the page. Or, you can just add highlight at the end of your object and you will see qtp highlight the element or the page you’re on.

      Browser(“Index:=1”).Page(“Index:=0”).highlight

      This will highlight your page.

      Browser(“index:=0”).Page(“title:=.*”).Link(“name:=TestName”).Highlight
      This will highlight your object
      Does this make sense?

      • aoreta

        Thanks for the code samples. I actually don’t have any problems in controlling the selection of the Links “Tab 1” and “Tab 2” under Advanced Control Practice Exercise.

        I am using the following code to toggle the selection from one link to another:
        Set txtCheck1 = Browser(“index:=0”).Page(“title:=.*”)
        txtCheck1.Link(“name:=Tab 2”).Click

        What I’m trying to figure out now is how to verify the output text being shown, respective to the link selected. Like if you select link “Tab 1”, at the bottom section, the text will show as “This is tab 1”, and if link “Tab 2” is selected, the text “This is tab 2” will show.

        I tried this code to determine if I select link “Tab 2” and tried to look for the text “This is tab 1”, I am expecting an error since the text that should show in the UI must be “This is tab 2”. However, no error was encountered and the the text “This is tab 1” is being returned by the message box.
        evaltxtCheck1 = txtCheck1.WebElement(“html tag:=P”,”innertext:=This is tab 1″).GetROProperty(“outertext”)
        msgbox evaltxtCheck1

        I’m not quite sure on how to do the checking for the text output and I think my approach is wrong. Can you suggest a way on how to do this? If you could also try to see the advanced control exercises and see what I’m trying to do. I would really appreciate it…Thanks.

        • QTPtutorialnet

          So, if I understand you correclty, seems like yhou want to be able to click a tab and know which tab is selected. This is a perfectly reasonable exercise.

          First, let’s tackle the tabs. If I look at the HTML of the tabs, I see this

          Tab 1

          If I switch to tab 2, i see this for tab 1

          Tab 1

          and this for tab 2

          Tab 2

          So, what this tells me is that the active tab is the one with the class=”et_pb_tab_active”. So that means you need to select a tab, then getROproperty of class and make sure that it’s “et_pb_tab_active”. This will tell you that it’s selected.

          Next, let’s look at the text. With tab 2 selected, I see

          This is tab 1

          This is tab 2

          With tab 1 selected, i see

          This is tab 1

          This is tab 2

          So, what this HTML tells me is that when a certain tab is selected, there are many attributes that we can use to figure something out. You can try to find the “div” that has attribute “display=block” or “opacity=1″ or even class=”et_pb_tab clearfix et_pb_active_content et-pb-active-slide”. This will give you the active tab element. Then you use getRoProperty of that element to get the text inside of the tag.

          Try this and let me know how it works out. We are going to have a large course on element identification soon. That will help you with reading HTML and understandiong how to identify elements.

          • aoreta

            Thanks a lot for the suggestion. I was able to successfully recognize the text “This is Tab 1” and “This is Tab 2” by getting the element style used for this WebElement, using GetROProperty(“style/opacity”).

            Bummer is that the class used slightly differs when switching the selection from Tab 1 to Tab 2 or vice versa. From the HTML inspection, if Tab 1 is selected, Tab 2 would have “class:=et_pb_tab clearfix et_pb_active_content et-pb-active-slide”. However, if Tab 2 is selected, Tab 2 would have “class:=et_pb_tab clearfix et-pb-active-slide”. So they have a difference of “et_pb_active_content”.

            By the way, I tried to use special character ‘ * ‘ to take in place “et_pb_active_content” but is seems not to work. I thought that I could try .WebElement(“class:=et_pb_tab clearfix * et-pb-active-slide”).GetROProperty(“style/opacity”) so I could only have 1 line to distinguish both Tab 1 and Tab 2. How can you use regular expression in this case?

            • QTPtutorialnet

              Hey. Regular expressions are the correct route to go to in this case. However, your syntax is not correct. Use .* instead of just * and it should work.

              • aoreta

                Thanks for correcting my syntax error for the the reg expression. Now my code works fine.

            • QTPtutorialnet

              Also, why don’t u select the tab like before, use the class value to make sure that it’s selected, extract value of that tab.

Pin It on Pinterest

Clef two-factor authentication