Results 1 to 6 of 6
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Need with getElementById


    Hello everyone,

    I want to access from my Access app to an email (the idea is to make like a license, if it can get in, it shows the "password" is still working as well as the license), if not I will add to close IE and Application.quit

    The issue I have is that I cannot find the "id" of the login button on the webpage using inspect element and I don't know if there is an other option than getElementById or maybe I am doing something wrong on the identification of my login button on the website https://mail.ionos.mx/

    Code:
    Sub Key()
    
    Dim email As String
    Dim password As String
    
    ' open IE, navigate to the desired page and loop until fully loaded
        Set IE = CreateObject("InternetExplorer.Application")
        my_url = "https://mail.ionos.mx/"
            
    IE.Visible = 1
    'apiShowWindow IE.hwnd, SW_MAXIMIZE
    apiShowWindow IE.hwnd, SW_SHOWMINIMIZED
    
        With IE
            .Visible = True
            .Navigate my_url
    
    Do Until Not IE.Busy And IE.ReadyState = 4
            DoEvents
        Loop
    
    End With
    
    ' Input the userid and password
        IE.Document.getElementById("login-form-user").Value = "name@domain.com.mx"
        IE.Document.getElementById("login-form-password").Value = "pssword#!"
    
    ' Click the "login" button
    'Here is my issue I cannot find the id for the button
    
        IE.Document.getElementsById("submit").Click
        
        Do Until Not IE.Busy And IE.ReadyState = 4
            DoEvents
        Loop
    
    End Sub
    Further I would like to update this "Internet Explorer to Edge or Chrome"....
    Thanks in advance for the help!!!
    Last edited by charly.csh; 12-20-2022 at 11:18 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Link you posted doesn't work.

    I use:

    IE.Document.all.Item("Submit").Click

    Do you have Option Explicit at top of module headers?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    309
    Hey there, mate.

    You can use this code to do what you want:
    Code:
    Sub Login()
        Dim URL As String = "https://mail.ionos.mx/"
        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")
        ie.Visible = True
        
        ' Navigate to the login page
        ie.Navigate URL
        
        ' Wait for the page to load
        Do While ie.ReadyState <> 4
            DoEvents
        Loop
        
        ' Fill the user and password fields
        With ie.Document
            .getElementById("login-form-user").setAttribute "value", "name@domain.com.mx"
            .getElementById("login-form-password").setAttribute "value", "pssword#!"
            .getElementsByTagName("button")(0).Click
        End With
    End Sub
    Keep in mind that there are several ways to reference stuff in the document. In this case, I'm just referencing the first "button" tag. But it could be done using other methods.
    Let me know how it goes.

  4. #4
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Yes I have Option Explicit at the top

    Thank you for the solution it worked perfectly!

  5. #5
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Good solution Edgar too
    It worked also good!!!

    Thanks!!!

  6. #6
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    309
    I'm happy to help, brother.

    You said you would like to switch to Edge or Chrome. The main options are perhaps Selenium and Puppeteer. Selenium for VBA is shady, it leaves you on your own, I don't recommend it. Puppeteer is top class, the best you will find, it uses javascript but what you're doing here is not too different and since it's maintained by Google itself, you can expect quality, reliability, good documentation and a vast community. The best thing is that you can make both Access and Puppeteer work together like a clock with a simple setup.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums