Consulting

Results 1 to 5 of 5

Thread: VBA MACRO Button click using a class instead of ID

  1. #1
    VBAX Regular
    Joined
    Apr 2020
    Posts
    9
    Location

    VBA MACRO Button click using a class instead of ID

    Dear Users,

    I am trying to run a sub that does the following:
    1. Access this website (https://clinicaltrials.gov/)
    2. Introduces some words in the boxes "Condition or disease" and "other terms"
    3. Clicks in the button "search"


    I did everything but point 3. I can't do point three because the button does not have an ID but has a class. I tried to use a class but then I can't run the command .Click I don't know exactly why.

    Here it is the code I have been using. When I run the macro I keep getting this error: Object does not support this method (this basically is telling me I can.t use the command .click with this getelement...

    PS: if you know any good resource for data scrapping please share with me I would be forever grateful


    CODE

    Sub pullDatafromweb()
    Dim IE As Object
    Dim doc As HTMLDocument


    'initializing the IE'


    Set IE = CreateObject("InternetExplorer.Application")


    'allows us to see the browser getting launched'


    IE.Visible = True


    'telling the object to go to the following object'


    IE.Navigate "https://clinicaltrials.gov"


    'tells the system to wait until the page is loaded before moving into the next line'


    Do While IE.Busy Or IE.ReadyState <> 4
    Application.Wait DateAdd("s", 1, Now)


    'puts the specificed values/strings in the search boxed'


    Loop
    Set doc = IE.document
    doc.getElementById("home-search-condition-query").Value = "GvHD"
    IE.document.getElementById("home-search-other-query").Value = "MSC"
    doc.getElementByTagClass("input.ct-searchButton.hp-searchButtonn").Click

    End Sub

    END CODE

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Just a precursory glance, everything looks normal, but isn't the class tag for the search button "ct-searchButton hp-searchButton" and not "input.ct-searchButton.hp-searchButtonn"?

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Tested and worked for me. The line you're looking for is:

    doc.getElementsByClassName("ct-searchButton hp-searchButton").Item(0).form.submit
    Edit: You may want to look here, they have an API.

  4. #4
    VBAX Regular
    Joined
    Apr 2020
    Posts
    9
    Location
    You are an ABSOLUTE LEGEND!!!!!

    Thank you so much!!!!!!!!

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    lol you're very welcome. I recommend taking a look at their API, it looks pretty nice. Controlling IE will only take you so far, and is not entirely efficient. It can be a good segue for coders because it has a visual you can see, but isn't efficient. There are also the security issues presented with using IE, because, well, it sucks. In the brief reading of their API, it looks like you can easily download multiple studies in a variety of formats.

Posting Permissions

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