本文介绍了iTunes的自动化连接VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过VBA自动执行报告.我曾在VBA工作,但无法通过代码登录iTunes网站.有人告诉我它是用iframe编写的,但我不知道.甚至我也无法在登录页面的输入框中输入用户名.

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 = "[email protected]"
    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

推荐答案

API听起来不错.整个页面的加载速度非常慢(至少对我来说),并且有一个iframe可以导航.

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

我会为vba使用硒基本包装,然后切换到iframe.有空的时候我会尝试改善这一点,但现在可以了.

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.

安装硒后,您将需要通过 VBE>添加参考.工具>对 Selenium Type库的引用.

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 "[email protected]"

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

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

这篇关于iTunes的自动化连接VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:49