dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to get attribute of tag using IHTMLelement object from IHTMLElementCollection

  1. #1
    Join Date
    Feb 2019
    Posts
    1

    Question How to get attribute of tag using IHTMLelement object from IHTMLElementCollection

    Hi,

    I'm just a beginner in Visual basic. I tried writing a code in which i want to access a webpage and click a button automatically. Since I couldn't find "ID" for that particular selection to perform a click, I'm using getelemenbytagname .Here is my code

    Code:
    Sub gg()
    
    Dim ie As New SHDocVw.InternetExplorer
    Dim HTMLDOC As MSHTML.HTMLDocument
    Dim HTMLA  As MSHTML.IHTMLElement
    Dim HTMLS As MSHTML.IHTMLElementCollection
    
    URL = "https://x-rates.com/"
    ie.Visible = True
    ie.navigate URL
    
    Do While ie.readyState <> READYSTATE_COMPLETE
    Loop
    
    Set HTMLDOC = ie.document
    Set HTMLS = HTMLDOC.getElementsByTagName("a")
    
    For Each HTMLA In HTMLS
        If HTMLA.getAttribute("href") = "http://www.x-rates.com/graph/?from=AUD&to=CAD" Then
            HTMLA.Click
    Next HTMLA
    
    End Sub
    The Object HTMLS has entire information of tag <a>. In the above code I had to loop though the HTMLS "collection" just to perform a single click. Is there a way to directly refer to particular attribute instead of using for each loop?
    Last edited by 2kaud; February 17th, 2019 at 06:10 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,910

    Re: How to get attribute of tag using IHTMLelement object from IHTMLElementCollection

    [When posting code, please use code tags. Go Advanced, select the formatted code and click '#'].

    Cheers!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)