Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用VBA在按钮中单击_Vba_Internet Explorer_Button_Click - Fatal编程技术网

尝试使用VBA在按钮中单击

尝试使用VBA在按钮中单击,vba,internet-explorer,button,click,Vba,Internet Explorer,Button,Click,这里是新手,试着点击一个按钮。我需要选择一个浏览器,导航到一个网站,填写一些字段,然后点击一个按钮。不行!这些代码正在打开IE、导航,但没有单击按钮 我使用下面的代码 Set ie = CreateObject("InternetExplorer.Application") With ie ie.Visible = False ie.navigate "My site" While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE: Do

这里是新手,试着点击一个按钮。我需要选择一个浏览器,导航到一个网站,填写一些字段,然后点击一个按钮。不行!这些代码正在打开IE、导航,但没有单击按钮

我使用下面的代码

Set ie = CreateObject("InternetExplorer.Application")
With ie
ie.Visible = False
ie.navigate "My site"
While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        .document.querySelector("My button ID > a").Click

        Stop
    End With
End Sub

OR THIS ONE

Sub Test2Felipe()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .navigate "My site"

        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        .document.querySelector("My button ID > a").Click

        Stop
    End With
End Sub
Set ie=CreateObject(“InternetExplorer.Application”)
与ie
可见=假
浏览“我的网站”
当ie.Busy或ie.readyState readyState_完成时:DoEvents:Wend
.document.querySelector(“我的按钮ID>a”)。单击
停止
以
端接头
还是这个
子Test2Felipe()
Dim ie成为新的InternetExplorer
与ie
.Visible=True
.浏览“我的网站”
当.Busy或.readyState时readyState\u完成:DoEvents:Wend
.document.querySelector(“我的按钮ID>a”)。单击
停止
以
端接头

通常,我们可以使用getElementByIdGetElementsByCassName方法或getElementsByName方法从网页访问元素,根据您的网站html资源,我建议您可以使用以下代码访问相关元素并单击按钮:

Public Sub ClickTest()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate2 "https://www4.unimedpoa.com.br/COOPERADO/Mobile/Autenticacao/Login"

        While .Busy Or .readyState <> 4: DoEvents: Wend

        'find the textbox and fill value
        ie.Document.getElementById("Usuario").Value = "test"
        ie.Document.getElementById("Senha").Value = "test"

        'Click the button
        ie.Document.getElementsByName("ActionButton")(0).Click  

    End With
End Sub
公共子点击测试()
模糊的物体
设置ie=CreateObject(“InternetExplorer.Application”)
与ie
.Visible=True
.导航2“https://www4.unimedpoa.com.br/COOPERADO/Mobile/Autenticacao/Login"
忙时或准备时状态4:DoEvents:Wend
'查找文本框并填充值
ie.Document.getElementById(“Usuario”).Value=“测试”
ie.Document.getElementById(“Senha”).Value=“测试”
'单击按钮
ie.Document.getElementsByName(“操作按钮”)(0)。单击
以
端接头
更多详细信息,请查看以下链接:

编辑

尝试通过“任务管理器”关闭所有explorer实例,然后在中等完整性级别使用internet explorer,代码如下

Public Sub ClickTest()
    Dim ie As New InternetExplorerMedium
    With ie
        .Visible = True
        .Navigate2 "https://www4.unimedpoa.com.br/COOPERADO/Mobile/Autenticacao/Login"

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

        'find the textbox and fill value
        ie.Document.getElementById("Usuario").Value = "test"
        ie.Document.getElementById("Senha").Value = "test"

        'Click the button
        ie.Document.getElementsByName("ActionButton")(0).Click

    End With
End Sub
公共子点击测试()
Dim ie作为新的InternetExplorerMedium
与ie
.Visible=True
.导航2“https://www4.unimedpoa.com.br/COOPERADO/Mobile/Autenticacao/Login"
忙时或准备时状态4:DoEvents:Wend
'查找文本框并填充值
ie.Document.getElementById(“Usuario”).Value=“测试”
ie.Document.getElementById(“Senha”).Value=“测试”
'单击按钮
ie.Document.getElementsByName(“操作按钮”)(0)。单击
以
端接头

[注意]请记住添加Microsoft Internet控件的参考

您可以发布有关超链接的相关HTML资源吗?对于我们来说,提供正确的方法来查找超链接可能会更容易。当然!它是“”。请用“test”填充用户框,用“test”填充密码框,然后点击“Acessar”按钮。您可以查看我的回复并参考代码,我的回复很好。错误出现在“While.Busy或.readyState 4”错误表中。错误表:来自的Busy方法失败“…我解决了此错误,执行此操作”直到ie.ReadyState ReadyState_完成循环“现在,错误在这一行”ie.Document.getElementById(“Usuario”).Value=“test”错误消息:来自对象“IWebBroswer2”的方法“Document”失败“@Vaz,尝试通过“任务管理器”关闭所有explorer实例,然后以中等完整性级别使用internet explorer,请参考以上编辑的代码。工作正常\0/\0/登录后,我正在使用此方法单击页面中的其他按钮。但是,我怎样才能得到这种类型的按钮?