Results 1 to 4 of 4

Thread: click <a> link without href in webbrowser, how?

  1. #1

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    click <a> link without href in webbrowser, how?

    am trying to click an <a> link that dosen't have href

    for example
    html Code:
    1. <a class="classname">
    2.     <div class="classname2"></div>
    3.     <span class="span">spantext</span>
    4. </a>

    how do i do this, this dosen't work?
    vb Code:
    1. webbrowser.Document.All("classname").Click
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: click <a> link without href in webbrowser, how?

    Well <a> denotes an anchor try this.

    Edit:

    webbrowser.Application.Document.All("classname").Click

    Note the part in bold. Also, make sure "webbrowser" is actually the name of your web browser.
    Last edited by Nightwalker83; Apr 13th, 2011 at 06:05 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: click <a> link without href in webbrowser, how?

    classname is the value for the class property of the element, where you are trying to use it you need the value of the name property, which it does not have, you need to loop through the elements to find the correct one based on some property, then click it

    try like
    vb Code:
    1. for each ele in wb.document.all
    2.   if ele.innertext = "spantext" then ele.click: exit for
    3. next
    i did not test this so may need a bit of tweaking

    edit:thinking about this, it would be improved
    vb Code:
    1. for each ele in wb.document.getelementsbytagname("a")
    you may also need to use
    vb Code:
    1. if instr(ele.innerhtml, "spantext") > 0 then ele.click
    of course if spantext is common to other elements, you may need to find someother property value to select the correct anchor
    Last edited by westconn1; Apr 13th, 2011 at 08:29 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: click <a> link without href in webbrowser, how?

    @Nightwalker83
    I get this error
    Code:
     91 Object variable or With block variable not set
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width