簡體   English   中英

VBA 和 Selenium WebDriver 的罕見網站登錄問題

[英]Uncommon Website Login Issue with VBA and Selenium WebDriver

我已經在 Excel 2016 中使用 VBA 宏以及 Chrome 和 Selenium WebDriver 登錄到許多不同的網站,但我沒有成功登錄以下代碼所示的網站。

' Open the "AARP" web page
WDriver.Start "chrome"
WDriver.Window.Maximize
WDriver.Get "https://www.medicare.uhc.com/AARP"

Application.Wait (Now + TimeValue("0:00:05"))   

' Click the "Sign In" button
WDriver.FindElementByXPath("/html/body/div[4]/div/div[1]/div[2]/div/div/div/main/section/div/div[1]/div/button[1]").Click

' Wait until the page is fully loaded
Application.Wait (Now + TimeValue("0:00:10"))

' Login
WDriver.FindElementById("EMAIL").SendKeys ("")     ' focus
WDriver.FindElementById("EMAIL").SendKeys ("abc")
Application.Wait (Now + TimeValue("0:00:02"))

WDriver.FindElementById("PASSWORD").SendKeys ("")  ' focus
WDriver.FindElementById("PASSWORD").SendKeys ("123")
Application.Wait (Now + TimeValue("0:00:02"))

WDriver.FindElementById("submitBtn").Click

' Do stuff

我可以看到 EMAIL 地址和密碼已正確插入,但是當單擊提交按鈕時,我從網站收到以下錯誤消息,“錯誤:輸入的用戶名和密碼組合與我們的記錄不匹配。”

EMAIL 輸入框的源代碼是

<input id="EMAIL" class="form-control ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" type="text" name="EMAIL" ng-model="sm.userInput" placeholder="" required="required" ng-blur="isValidUserNameEmail()" aria-invalid="true" style="">

PASSWORD 輸入框的源代碼非常相似。

有熟人建議我需要使用javascript(ExecuteScript),然后在設置EMAIL后調用“isValidUserNameEmail()”。

我對如何執行此步驟一無所知,並希望獲得有關如何對此步驟進行編碼的幫助。 另外,“isValidUserNameEmail()”代碼到底在做什么? 有沒有辦法在不使用 javascript 的情況下完成此操作?

預先感謝您的幫助...羅恩

我將回答關於what exactly is the "isValidUserNameEmail()" code doing的第二部分:

正如您可能從名稱中猜到的那樣,它正在對通過 angular ng-blur 事件調用的用戶輸入字段執行驗證。

您可以在 js 文件https://www.healthsafe-id.com/controllers/login/login-ce5235a2c825372facef0f2b619e467a.js 中找到您需要了解的大部分內容。

函數定義在第 624 行。您將看到它調用了一個自定義函數來檢查該字段是否為空。 它使用條件三元運算符 (?)根據為空測試的結果決定要做什么。 如果為空,則查找已保存的值,否則查找用戶輸入。 無論哪種方式,它都會將返回值分配給一個變量,然后將該變量傳回同一個函數以測試是否仍然為空,即'' 如果不是,您將獲得''分配,如果是,它將piEMAILError設置為從自定義函數(來自 Optum. United 合作伙伴的 AEM 組件)返回的值。 它傳入EMUsernameRequired作為keyAEM參數。

在此調用函數中還有一系列其他函數調用,例如第 208 行和第 218 行。這些調用的結果是返回https://www.healthsafe-id.com/content/healthsafeid/aarp/signin?HTTP_LANGUAGE=en概述的默認響應https://www.healthsafe-id.com/content/healthsafeid/aarp/signin?HTTP_LANGUAGE=en

在上面的鏈接中,您會發現Username is required作為與密鑰EMUsernameRequired_v2關聯的默認值, The username and password combination entered does not match our recordsSigninFailedNoRecord_v2關聯The username and password combination entered does not match our records 后者是您目前得到的回應,暗示這些值要么錯誤,要么未被識別。

它是有角度的,所以它非常復雜,你可以繼續挖掘和跟蹤,但有些決定可能是服務器端的。 基本上,初始函數在輸入字段失去焦點時被調用。


為了進入登錄頁面,使用短的 css 選擇器比使用長的 xpath 更健壯,例如

.FindElementByCss(".login button").click

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM