[英]SeleniumBasic VBA TakeScreenshot Element outside of the screenshot Error
[英]Unable to find element using seleniumbasic for vba
我正在嘗試使用 SeleniumBasic 為 Excel VBA 自動化數據輸入過程。 我已經能夠通過在登錄頁面上找到必要的元素選擇器來登錄網站。 之后我需要在登錄后進入其他的索賠條目頁面( https://claims.curacel.co/#/pro/claims/new ),我必須將鼠標移動到一個按鈕(新索賠),單擊時顯示另一個按鈕(Single Claim)以到達( https://claims.curacel.co/#/pro/claims/new ),但是在檢查第一個按鈕以找到可用的選擇器時,VBA 仍然返回錯誤“未找到元素”
這是登錄代碼(我也評論了我在查找按鈕元素方面的一些嘗試)
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>
我錯過了什么?
要對顯示另一個按鈕Single Claim的New Claim按鈕執行鼠標 Hover ,您可以使用以下定位器策略:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.