自动化错误。通过 Selenium 和 VBA 使用 Excel 的灾难性故障错误

Automation error. Catastrophic failure error using Excel through Selenium and VBA

我正在尝试通过 selenium VBA 填写网络表单。我使用了一些曾经运行良好的代码。现在我已经更新到新版本的办公室,现在当我尝试相同的代码时它说

" Automation error. Catastrophic failure"

    Sub Rel_join()

        Dim bot As New ChromeDriver
        bot.Start "chrome", "******"
        Dim x, y,w
        bot.Get "/"
        'bot.Window.Maximize
        'login
        bot.Wait 1500
        bot.FindElementByXPath("//*[@id='lang-menu']/li[5]/a").Click
        bot.Wait 500
        'select department
        d = "********"

        Set ele = bot.FindElementById("ddldept").AsSelect
        ele.SelectByText [d]
        bot.FindElementByXPath("//input[@id='txtusername']").SendKeys "*****"
        bot.FindElementByXPath("//input[@id='txtpwd']").SendKeys "******"
        Stop
        'Navigate to service book
        bot.Get "***********URL"

           For y = 4 To 4
       ** x = ThisWorkbook.Sheets("sheet1").Range("w" & y).Value**
        cSCRIPT = "document.getElementById('txtempcd').value='" & x & "'"
        bot.ExecuteScript cSCRIPT
        Stop
        cSCRIPT = "document.getElementById('Save').click()"
        bot.ExecuteScript cSCRIPT
        bot.SwitchToAlert.Accept
        bot.Wait 3000
        Next y
    End Sub

我也注意到这个错误显示在行

 ** x = ThisWorkbook.Sheets("sheet1").Range("w" & y).Value**

这个错误信息...

Automation error. Catastrophic failure

...表示在访问基于 Office 365[=30 的 excel sheet 时出现 自动化错误 =].


根据 Automation error: Catastrophic failure Problem with Excel 2016 中的讨论,主要问题与 Office 365Excel 的版本有关 与提供给企业用户的版本不同。


解决方案

最简单的解决方案是将文件另存为 Excel 二进制工作簿 并在 自动测试 中使用它