本文介绍了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 使用 selenium basic wrapper 并切换到 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.

安装 selenium 后,您需要通过 VBE > 添加引用.工具 >引用 Selenium 类型库.

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-01 04:20