Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

excel - VBA Selenium Chrome : How to Change Link

I just started using VBA Selenium. I login to the site with password / username via Chrome.

I want to:

1- I Must Change the link after logging in.

2-Chrome will remember my password and username when the connection changes (it doesn't remember the connection and username / password, so when I renew it, it returns to the home screen and asks for username / password) (<-----I couldn't)

3-Receiving data from the connection.

Help please!

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

Tried but Not Working Codes

Driver.get ("https://ybs.hmb.gov.tr/ybs/raporlar/tasinir/tasinir-il-icmal")

question from:https://stackoverflow.com/questions/66062445/vba-selenium-chrome-how-to-change-link

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...