Automation of iTunes connect VBA

自古美人都是妖i 提交于 2021-02-02 09:57:24

问题


I am trying to automate a report through VBA. I have worked in VBA but not able to login in iTunes website through codes. Someone told me that it is written in IFrame, but i have no idea. Even i am not able to put my username in input box of login page.

https://itunesconnect.apple.com/login

Dim HTMLdoc As HTMLDocument    
Dim MyBrowser As InternetExplorer

Sub check()

    Dim MyHTML_element As IHTMLElement
    Dim MyURL As String

    MyURL = "https://itunesconnect.apple.com/login"
    Set MyBrowser = New InternetExplorer

    MyBrowser.Silent = True
    MyBrowser.navigate MyURL
    MyBrowser.Visible = True

    Do
    Loop Until MyBrowser.readyState = READYSTATE_COMPLETE

    Set HTMLdoc = MyBrowser.document

    HTMLdoc.getElementsByID("account_name_text_field").Value = "username@outlook.com"
    HTMLdoc.all.Password.Value = "password"

    For Each MyHTML_element In HTMLdoc.getElementsByTagName("input")

        If MyHTML_element.Type = "sign-in" Then MyHTML_element.Click: Exit For

    Next

Err_Clear:

    If Err <> 0 Then

        Err.Clear

        Resume Next
    End If
End Sub

回答1:


API sounds like a good idea. The whole page is very slow loading (for me at least) and there is an iframe to navigate.

I would go with selenium basic wrapper for vba and switch to the iframe. I will try to improve this when I have time but for now this works.

After installing selenium you will need to add a reference via VBE > Tools > References to Selenium Type library.

Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver, t As Date, ele As Object
    Set d = New ChromeDriver
    Const URL = "https://itunesconnect.apple.com/login"
    Const WAIT_TIME_SECS As Long = 30
    t = Timer
    With d
        .Start "Chrome"
        .get URL
        Do
            DoEvents
            If Timer - t > WAIT_TIME_SECS Then Exit Do
            On Error Resume Next
            .SwitchToFrame "aid-auth-widget-iFrame"
            Set ele = .FindElementByCss("#account_name_text_field")
            On Error GoTo 0
        Loop While ele Is Nothing

        If ele Is Nothing Then Exit Sub
        ele.SendKeys "Joe.Bloggs@aol.com"

        .FindElementByCss("#sign-in").Click

        'Other code....
        Stop                                     '<=Delete me later
        .Quit
    End With
End Sub


来源:https://stackoverflow.com/questions/52195518/automation-of-itunes-connect-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!