SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Junior Member
    Join Date
    Apr 2007
    Location
    Orange County, California
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    how to click a link preceeded by certain text

    Dear all,

    Sorry to ask such a noob question. I am new to Mercury qtp and visual basic. I am a competent programmer in cpp and intermediate - advanced in java. I will most probably be joining your sqaf:qtp community since I need to learn many things about mercury. So following the guides:

    QTP Version - 9.1
    Addins Loaded - web
    Application Protocol Testing - none
    Any non-standard controls involved - none

    Problem details - There is a image where onclick will execute a javascript function. The html command for the image is identical for multiple cases. I need to click the image where it is preceded by the onclick command I want. I read the tutorial and parameterized my variables. Unfortunately, in the first iteration the link was on top because the list is sorted alphabetically. In the second iteration the image to click was not on top of the list and something else got deleted by qtp instead. The item that was at the top of the list in the second iteration. co-workers unhappy.

    What searches you have tried - I looked around and found some guides and references. But I can't map the references to qtp, such as the browser, page, and frame objects. I tried to find an api / reference for these objects but was able to instead find multiple vb/.NET references. I found many examples of how to specify the link i want in descriptiveProgramming and objectRepository I think they are called. Also many examples of different parameters to pass.

    Solutions you have tried - I tried looking at my link in the object repository and expert view. Since the image in html is only an img src="xxx", and is identical to multiple other images on the screen in both display and source, there is not something I can pinpoint for qtp to detect. The <img> tag is preceded by a <td> tag with an onclick event embedded.

    example:
    <font class="small">Code:</font><hr /><pre>
    &lt;tr&gt;
    &lt;td&gt;&lt;a href="#" onclick="editDataSource(1)" class="topNav"&gt;PTQA1&lt;/a&gt; &lt;img src="greenChk.gif" alt="Active" /&gt;&lt;/td&gt;
    &lt;td style="cursor:hand;" align="center" onclick="deleteDataSource('1', 'PTQA1')"&gt;&lt;img src="delete_icon.gif" width="14px" height="14px" border="0" alt="Delete" /&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
    &lt;td&gt;&lt;a href="#" onclick="editDataSource(20)" class="topNav"&gt;jays_data source NAME!!!&lt;/a&gt; &lt;img src="greenChk.gif" alt="Active" /&gt;&lt;/td&gt;
    &lt;td style="cursor:hand;" align="center" onclick="deleteDataSource('20', 'jays_data source NAME!!!')"&gt;&lt;img src="delete_icon.gif" width="14px" height="14px" border="0" alt="Delete" /&gt;&lt;/td&gt;
    &lt;/tr&gt;

    </pre><hr />

    Very long winded, sorry, but I don't know how to describe it more precisely. I am happy to learn any method to click the image after the html I want, but happiest to learn multiple ways to make qtp do what I want.

    many thanks in advance,

    warren

  2. #2
    Junior Member
    Join Date
    Feb 2004
    Location
    Hyderabad
    Posts
    24
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    Hi,
    verify below code can solve your promblem.First find the index of the object and replace that value with intIndex and u can also give image file name .
    If this solution is not worked. use for loop to identify in which row the image is and give that row number as index value.
    set objImage= Description.Create()
    objImage("image type").Value = "Image Link"
    objImage("html tag").Value = "IMG"
    objImage("Index").Value = intIndex ' Give index number of the image
    objImage("outertext").Value = strObjText' text of the image
    objImage("file name").Value = strAdditional ' file name of the image
    Ravindra

  3. #3
    Senior Member
    Join Date
    Oct 2005
    Posts
    240
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    Hi Warren, You can do this type of thing with DOM. Here's the general idea. Get the list of links in the table or page. Find the one you want. Get the parent. In this case a &lt;td&gt;. Then get the next sibling which has your onclick function. I think that's all you need. (If you really want the img try the firstChild of the nextSibling.)
    Sample:
    <font class="small">Code:</font><hr /><pre>Set l = Browser("...").Page("...").WebTable(...).Object.Ge tElementsByTagName("A")
    For each e in l
    msgbox e.onclick
    set n = e.parentNode
    msgbox n.nextSibling.onclick
    Next
    </pre><hr />
    M.

  4. #4
    Junior Member
    Join Date
    Apr 2007
    Location
    Orange County, California
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    thanks to both, but in this case MJP has the best working answer for me I feel. Here's your reward of a virtual pint of the finest Irish Ale.

    Since this is my first post on this forum, I will also give to all a great link for a good laugh. Pass it around to ur buddies.

    http://thefunniest.info/top.html

  5. #5
    Junior Member
    Join Date
    Apr 2007
    Location
    Orange County, California
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    sadly, a few hours later I am unable to use the answer MJP gave me. I looked at
    http://developer.mozilla.org/en/docs/DOM:element
    the mozilla DOM reference. After a little playing around I figured out that I had a node element. But the thing I need to do is search the onclick to see if it contains a certain string of text. I could not figure out how to do this. I tried to convert to string but each try did not work. I tried calling className on it but it gave an error message. Each example I find on the web about how to use onclick in DOM shows how to assign an onclick, but not how to parse one.

    Alternately, if anybody could show me how to find the text that is between the &lt;A&gt; tags, I could traverse from there to click the corresponding &lt;IMG&gt; tag I need to click on.

    Mercury QTP sure has a learning curve. I've been reading a vb book, the qtp users guide, and forum postings all day long. I feel like mah brains is jellos!

  6. #6
    Senior Member
    Join Date
    Oct 2005
    Posts
    240
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    Hi, You can search the onclick's function call and parameters. You can fire the onclick event too.
    hth,
    M.
    <font class="small">Code:</font><hr /><pre>For each e in l
    Set n = e.parentNode
    myString = cStr( n.nextSibling.onclick)
    If instr( myString, "jays_data") &gt; 0 Then
    msgbox "Found what were looking for: "&amp; myString
    'Fire the onclick event.
    n.nextSibling.click
    end if
    Next </pre><hr />

  7. #7
    Junior Member
    Join Date
    Apr 2007
    Location
    Orange County, California
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    Many thanks again.

    Dear MJP and all others who can answer this
    I actually tried the CStr function with the onclick value but it didn't work because I had the keyword set in front ex:
    <font class="small">Code:</font><hr /><pre>
    Set ocString = CStr(n.nextSibling.click)
    </pre><hr />
    as opposed to MJP's solution where, in his line 3 in the post directly above, it didn't have the set keyword. So why did that mess it up for me?

  8. #8
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    Before i could help i wanted to know if you are using IE or some other browser? Because the two have different DOM behaviour

  9. #9
    Junior Member
    Join Date
    Apr 2007
    Location
    Orange County, California
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    IE

  10. #10
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: how to click a link preceeded by certain text

    <font class="small">Code:</font><hr /><pre>
    &lt;td&gt;&lt;a href="#" onclick="editDataSource(1)" class="topNav"&gt;PTQA1&lt;/a&gt; &lt;img src="greenChk.gif" alt="Active" /&gt;&lt;/td&gt; &lt;td style="cursor:hand;" align="center" onclick="deleteDataSource('1', 'PTQA1')"&gt;&lt;img src="delete_icon.gif" width="14px" height="14px" border="0" alt="Delete" /&gt;&lt;/td&gt;
    </pre><hr />

    Btw I could understand the exact issue...

    1. you have the link PTQA1 and you want to click the Green Check image next to it?
    2. Do you want to click the delete link also against it?
    3. And also you will always have the link against which you want to click these images or not?

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:08 AM.

Copyright BetaSoft Inc.