使用Selenium Basic for VBA查找元素



我正在尝试使用Selenium Basic for Excel VBA自动化数据输入。

我已经能够通过在登录页面上定位必要的元素选择器来登录网站。

之后,我需要进入索赔条目页面(https://claims.curacel.co/#/pro/claims/new)
要在登录后执行此操作,我必须将鼠标移动到显示另一个按钮(单个索赔(的按钮(新索赔((https://claims.curacel.co/#/pro/claims/new)单击时。

但是,在检查第一个按钮以查找可用的选择器时,VBA返回一个错误。

"ELEMENT NOT FOUND";

这是登录的代码(我还评论了我在查找buttons元素方面的一些尝试(。

Sub Curacel()
    Dim Findby As New Selenium.By
    Set WB = New Selenium.ChromeDriver
        
    WB.Start
    WB.Get "https://claims.curacel.co/#/login"
      
    'error handling, if element property on the webpage has changed e.g name of an element or i.d
    If WB.IsElementPresent(Findby.ID("input-live")) = False Then
        MsgBox "Webpage Element(s) has been changed, kindly Alert Software Developer!", vbExclamation + vbInformation, "Contact Developer"
        WB.Quit
    End If
        
    ''input password and credentials
    ''UserName
    WB.FindElementById("input-live").SendKeys "almadinacliniczaria@gmail.com"
    ''Password
    WB.FindElementByXPath("/html/body/div[2]/login-component/div/div/div[1]/div[2]/form/div[2]/input").SendKeys "almadina071"
    ''loginClick
    WB.FindElementByXPath("/html/body/div[2]/login-component/div/div/div[1]/div[2]/form/div[3]/button").Click
        
    ''ATTEMPTS returning ELEMENT NOT FOUND
    'WB.FindElementById("dropdownMenuButton").Click
    'WB.FindElementByXPath("/html/body/div[2]/provider-app-component/dashboard-component/div/div[2]/div[1]/div/nav/div/ul/div/div[1]/div/button/span").Click
        
    'WB.FindElementByXPath("/html/body/div[2]/provider-app-component/dashboard-component/div/div[2]/div[1]/div/nav/div/ul/div/div[1]/div/button/text()").Click
       
    'WB.Mouse.MoveTo (WB.FindElementByCss(".dropdown"))
        
End Sub

这是HTML代码:

<button data-v-d3dab69e="" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn dropdown-toggle new-claim">
                                New Claim<span data-v-d3dab69e="" class="ml-2"><em data-v-d3dab69e="" class="fa fa-chevron-down"></em></span></button> 
                                New Claim
<span data-v-d3dab69e="" class="ml-2"><em data-v-d3dab69e="" class="fa fa-chevron-down"></em></span>
<em data-v-d3dab69e="" class="fa fa-chevron-down"></em>
<::before></::before>
<em data-v-d3dab69e="" class="fa fa-chevron-down"></em>
<span data-v-d3dab69e="" class="ml-2"><em data-v-d3dab69e="" class="fa fa-chevron-down"></em></span>
<button data-v-d3dab69e="" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn dropdown-toggle new-claim">
                                New Claim<span data-v-d3dab69e="" class="ml-2"><em data-v-d3dab69e="" class="fa fa-chevron-down"></em></span></button>

要将鼠标悬停在新索赔按钮上,以显示另一个按钮单个索赔,您可以使用以下定位器策略:

Dim actions As Selenium.actions
WebElement we = driver.FindElementByXPath("//button[@id='dropdownMenuButton' and contains(., 'New Claim')]")
WB.actions.MoveToElement(we).perform
driver.FindElementByXPath("//div[@aria-labelledby='dropdownMenuButton']//a[@class='dropdown-item' and text()='Single Claim']").Click

最新更新