問題描述
VBA Selenium Chrome:如何更改鏈接 (VBA Selenium Chrome : How to Change Link)
我剛開始使用 VBA Selenium。我通過 Chrome 使用密碼/用戶名登錄網站。
我想:
1‑ 我必須在登錄後更改鏈接。
2‑ Chrome會在連接改變時記住我的密碼和用戶名(它不記得連接和用戶名/密碼,所以當我更新它時,它會返回主屏幕並要求輸入用戶名/密碼)(<‑‑‑‑ ‑ 我不能)
3‑從連接接收數據。
請幫忙!
Private Keys As New Selenium.Keys
Private driver As New Selenium.ChromeDriver
Sub test100()
Const JS_NEW_WINDOW = "window.open(arguments[0], name);"
driver.Get "https://ybs.hmb.gov.tr/"
driver.FindElementById("identification", timeout:=10000).Clear
driver.FindElementById("identification").SendKeys "UserName"
driver.FindElementById("password").SendKeys "Pass*"
driver.FindElementByClass("mly‑login‑button").Click
driver.ExecuteScript JS_NEW_WINDOW, "https://ybs.hmb.gov.tr/ybs/raporlar/tasinir/tasinir‑il‑icmal"
driver.SwitchToNextWindow
Stop
End Sub
試過了但不工作的代碼
Driver.get(“https://ybs.hmb.gov.tr/ybs/raporlar/tasinir/tasinir‑il‑icmal”)
參考解法
方法 1:
ExecuteScript
will always invoke the new url in the adjacent tab or within a new window.
Try to invoke the new url in the same tab / window as follows:
driver.Get "https://ybs.hmb.gov.tr/"
driver.FindElementById("identification", timeout:=10000).Clear
driver.FindElementById("identification").SendKeys "UserName"
driver.FindElementById("password").SendKeys "Pass"
driver.FindElementByClass("mly‑login‑button").Click
driver.Get "https://ybs.hmb.gov.tr/ybs/raporlar/tasinir/tasinir‑il‑icmal"
(by Ahmet、undetected Selenium)