自动化Internet Explorer和SendKeys

问题描述

我编写了一个VBA代码,该代码通过Internet Explorer打开了一个网站,并输入了我的电子邮件和密码,最后将网站中的一些数据提取到Excel中。

我的问题是,当我第一次执行我的代码时,它很混乱,将我的电子邮件和密码放入网站登录提示中。如果我再执行几次代码,往往会最终在登录提示中输入电子邮件和密码。

现在,我正在使用VBA的SendKeys函数,但我正在尝试对更好的替代方法进行一些研究。有人有建议吗?非常感谢。

Sub PullData()


    Dim IE As New InternetExplorer
    With IE
        .Visible = True
        .Navigate2 "https://NotRealwebsite.com/login"

        While .Busy Or .ReadyState < 4: DoEvents: Wend

        With .Document

            With .getElementById("email")
                .Focus
                SendKeys "xxxxyyy@xyz.com"
            End With

            SendKeys "{tab}"

            Application.Wait Now + TimeSerial(0,1)

            With .getElementById("password")
                .Focus
                SendKeys "Pswrd123"
            End With

            Application.Wait Now + TimeSerial(0,1)

            

            While IE.Busy Or IE.ReadyState < 4: DoEvents: Wend

        End With
       
    End With
IE.Document.getElementsByClassName("btn btn-primary-lg")(0).Click

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)