VBA函数获取“Argument Not Optional”错误

时间:2016-09-25 04:42:40

标签: vba excel-vba function selenium-webdriver arguments

我正在尝试修复使用Selenium1.0.23打开网站并登录的VBA。我的客户说一切都在他的结束,除了VBA必须输入错误的用户名和密码,因为该网站提供了错误的用户名 - 密码消息。 现在我得到了脚本并尝试运行它但是我卡在了“Argument Not Optional”的功能上。以下是剧本:

这是有错误的部分。它突出了“.setVariation”部分。

Private Function setVariationOnPage(browser As SeleniumWrapper.WebDriver, variations As Scripting.Dictionary) As Long
Dim name
For Each name In variations.keys
    ProductVariations.setVariation browser, variations(name)
Next name 
End Function

我相信上面的函数在一个单独的模块上调用另一个函数,因为它有一个模块名称ProductVariations和一个名为setvariation的函数。

Public Function setVariation(browser As SeleniumWrapper.WebDriver, ByVal name As String, value As String)
On Error GoTo setVariationError

Dim li As WebElement
Dim lis As Collection

Set lis = getVariationListItems(browser, name)
If lis Is Nothing Then
    GoTo setVariationError
    Exit Function
End If


For Each li In lis

    Dim link As WebElement
    Set link = getLinkFromVariationListItem(li)

    If LCase(Trim(getVariationValueNameFromListItem(li))) = LCase(Trim(value)) Then
        If InStr(li.getAttribute("class"), "active") = 0 Then
            link.Click
            ScrapingUtil.waitForPageToLoad browser
            If InStr(li.getAttribute("class"), "active") = 0 Then
                GoTo setVariationError
            End If
        End If
        Exit Function
    End If
Next li

setVariationError:
Dim msg As String
msg = "Unable to set variation: ""{name}"" = ""{value}"""
msg = Replace(msg, "{name}", name)
msg = Replace(msg, "{value}", value)
Err.Description = msg
Err.raise 1
End Function

然后显然这个函数调用另一个函数,该函数调用另一个函数。对它进行故障排除真是太糟糕了,我真的需要帮助。

1 个答案:

答案 0 :(得分:-1)

将参数设为可选..

 Public Function setVariation(browser As SeleniumWrapper.WebDriver, ByVal name As String, optional value As String).