Forum Discussion

programdoubts's avatar
programdoubts
Contributor
13 years ago

URGENT: how to get all the links under specific div/ panel only

HI All,



im shal new to TestComplete tool.



How to get all the links under specific div/ table/ panel



ex:



<div id="firstDiv">

<a href="1"> 1 </a>

<a href="2"> 2 </a>

<a href="3"> 3 </a>

</div>





<div id="secondDiv">

<a href="1"> 1 </a>

<a href="2"> 2 </a>

<a href="3"> 3 </a>

</div>



Now i wanna get all the links under "firstDiv" not under secondDiv



pls let me know how to write script in vb to get all the links under specific div tag



thanks in advance
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Ram,


     


    Actually, I don't quite understand why you are clicking each link on the page. If you want to check whether a link is valid, you'd better use this sample. It checks the accessibility of the page by using the MSXML2.XMLHTTP object.


     

  • Hi Tanya Gorbunova,



    Actually my application page contains like

    Left Panel and Right Panel frames



    in Left Panel im having few links,  suppose assume Left Panel contains 1,2,3... links (1st class, 2nd class, 3rd class.... links)



    When i click on Left Panel Link, Example 1st class link



    Now Right Panel will display all the 1st class student names



    Assume Right Panel contains students names like A, B, C....Z



    Now i will click on A student, then A student related details report will get



    Once the student report is displayed i will verify the details and click back



    Now page will back to student names list Panel (Right Panel)



    Now again i will click B student link, i will navigate to B studnet report, so on upto the last name



    if i complete in verifying all the names in Right Panel of 1st class students details



    Now i will click 2nd class link from Left Panel, now i will get all the 2nd class studentsdetails in Right Panel



    Now i will repeat the above steps to verify all the students in 2nd class



    like wise i will check all the classes links for Left Panel



    Now my problem is, when i click on 1st class link from Left Panel, all the 1st class students names will display in Right Panel

    When i click on A student from Right Panel, tool is not waiting until A student report is displaying



    for that after searching all the posts i have used 



    page.wait() method



    After using this method its working fine for some times, but some times it is not waiting



    The same script is working some times and failing in waiting until page loadsfully




    This is what im facing problem, pls let me know if u know the solution how to overcome this 



    pls find the attached screen shots for sample appliction view



    hope i have given clear idea about my application with screen shots.



    pls let me know if there is solution for this



    thanks in advance

  • Hi Ram,



    If the problem is the Wait() function, I guess this will help you:



    First approach: If you are sure of how many time it will take to load the frame, then use Delay function (for example, Delay(10000) will wait 10 seconds). It's not very pretty, but it's a way.



    Second approach: If you know which objects are on right frame (for example, the table object, or an icon, or whatever object you like), just keep searching for that object until it exists and is visible (or visible on screen). It will work always, but make sure to have a break condition in case of problems.



    Hope it helped

  • Hi Javier Coll,



    thanks for replying.



    yes the way u suggessted is also one of the correct way, but its not suggesstable



    we can use the way, which u have suggessted, only the suitation when the next navigated page is known, i.e when i know what will be the next navigated page only



    but here in my application i dont know what will be the next page, it will be random,

    so here tool need to wait until the page gets loaded fully.



    there is no other option for me, tool should wait until page gets loaded fully



    in other tools like Sahi tool having this option, it will wait until page gets loaded fully without fail and other adv is, it will support internal ajax also, internally it will check ajax request and wait until Ajax request is processed



    if this is possible with TestComplete tool, then it gonna will rock. Every thing is fine with TestComplete but it is not able to wait until page gets loadedfully



    For Automation tools this is the minimum feature, tool should take care of these things

    can't we handle these things with script ?  Yes we can do but its not suggesstable way 



    Seems TestComplete is not able to supporting these features. 



    Smartbear Team if ur tool supports these features, pls let me know





    Below is the script/ code which i have developed, pls let me know, if there is wrong with my script itself/ tool not able to support this feature








    Function fun_LinkTest


     


    Dim page, links, linksCount, link, URL, i, panel


    Dim PropArray, ValuesArray


      


    URL = "http://www.domain.com"


    Browsers.Item(btIExplorer).Run(URL)


     


    Set page = Sys.Browser("*").Page("*")


        


    Set panel = page.FindChild("idStr", "leftPanel", 14)


     


    If panel.Exists then


     


         PropArray = Array("ObjectType","visible")


         ValuesArray = Array("Link","true")

     


         links = panel.FindAllChildren(PropArray, ValuesArray, 9)


         Log.Message("Total No. of links: "& UBound(links))

     


          If UBound(links) > 0 Then 


               For i = 0 To UBound(links)


                   links(i).click()


               Next 


          End If 

     


    End if 


      


    End Function





    thank u all, who supported me till now. :)





  • Hi Ram,



    I think there has been a misunderstand. Test Complete allows you to wait until a page has been fully loaded, but it does not trigger when you click on a link. So, you have to add it on the script. In your code:




    If UBound(links) > 0 Then 


      For i = 0 To UBound(links)


        links(i).click()

        page = Sys.Browser("*").WaitPage("*", 5000)


      Next 


    End If



    This should wait until 5 seconds until the page is fully loaded (in javascript, document is ready). You should also search again the 'panel' container in case it is destroyed



    About the fact that you don't know what will be shown in the next screen when you click on a link, there is a big problem: you should. Try talking to your application development team to find a way to solve that, as it will help you developing faster and more secure automation scripts. If you want to know more, in my blog I talk a little about this.



    I hope it helped

  • Hi Javier Coll,



    thanks for reply.



    as per your suggession i have used 



    page = Sys.Browser("*").WaitPage("*", 20000)



    when i used this statement, im getting error

    Error: Object doesn't suuport this property or method



    pls let me know, why im getting this error



    im attaching error screen shot pls look into that



    One more thing i wanna update you,

    im not only facing waiting problem when i click on a link,

    when i enter username and password and click submit button,

    then my application will be navigating to home page,

    before it's  navigated to home page

    TestComplete tool is trying to execute next script(home page validation script), but still page is not yet loaded



    thanks 
  • Hi Ram,



    I'm not really sure... Try changing Sys.Browser("*") to Sys.Browser("iexplore") or the browser you are using.



    I just realized that WaitPage does not wait until the page is fully loaded, I'm sorry. But take a look at this article.



    The case with the submit button can be solved the same way as the links clicks. If the submit button redirects you to another web page, just change WaitPage("*") for WaitPage(<WEB_PAGE_URL>). 



    Edit: Maybe the error is caused because you have to write Set just before the assignement, I don't use vbs so I am not sure
  • Hi All,



    thanks to every one who supported me till now



    finally we have shifted to sahi tool,



    @Admin: you can close this issue



    once again thanks to every one