by sanmaodo » 16 Mar 2021, 16:58
Hello,
@burque505,非常感谢您的回复,抱歉,之前我没有把问题描述清楚。
我的需求是这样的:
1,在现有的浏览器窗口中...
2,在新标签页中...
3,打开网址并执行自动点击。
我找到了一个办法,但并不是很稳定,在测试过程中偶尔会出现问题,期待您对它进行改进。
首先,现有的浏览器窗口必须要添加参数打开:
Code: Select all
Run, Chrome.exe "--remote-debugging-port=9333"
然后,
Code: Select all
;https://www.autohotkey.com/boards/viewtopic.php?f=7&t=87159
SetBatchLines, -1
wd := ComObjCreate("SeleniumBasic.IWebDriver")
svc := ComObjCreate("SeleniumBasic.ChromeDriverService")
options := ComObjCreate("SeleniumBasic.ChromeOptions")
svc.CreateDefaultService.driverPath := ".\tools\SeleniumBasic"
svc.HideCommandPromptWindow := True
options.BinaryLocation := "C:\Program Files\Google\Chrome\Application\chrome.exe"
options.DebuggerAddress := "127.0.0.1:9333"
wd.New_ChromeDriver(svc,Options)
if WinExist("ahk_class Chrome_WidgetWin_1")
WinActivate
wd.ExecuteScript("window.open('https wyagd001.github.io /zh-cn/docs/AutoHotkey.htm')") Broken Link for safety
tabs :=wd.WindowHandles
n := tabs.MaxIndex()
wd.SwitchTo.Window(tabs[n])
wd.FindElementByXPath("//*[@id='head']/div/div[1]/ul/li[2]/button").click()
wd.Quit()
Hello, [mention]burque505[/mention],非常感谢您的回复,抱歉,之前我没有把问题描述清楚。
我的需求是这样的:
1,在现有的浏览器窗口中...
2,在新标签页中...
3,打开网址并执行自动点击。
我找到了一个办法,但并不是很稳定,在测试过程中偶尔会出现问题,期待您对它进行改进。
首先,现有的浏览器窗口必须要添加参数打开:
[code]Run, Chrome.exe "--remote-debugging-port=9333"[/code]
然后,
[code];https://www.autohotkey.com/boards/viewtopic.php?f=7&t=87159
SetBatchLines, -1
wd := ComObjCreate("SeleniumBasic.IWebDriver")
svc := ComObjCreate("SeleniumBasic.ChromeDriverService")
options := ComObjCreate("SeleniumBasic.ChromeOptions")
svc.CreateDefaultService.driverPath := ".\tools\SeleniumBasic"
svc.HideCommandPromptWindow := True
options.BinaryLocation := "C:\Program Files\Google\Chrome\Application\chrome.exe"
options.DebuggerAddress := "127.0.0.1:9333"
wd.New_ChromeDriver(svc,Options)
if WinExist("ahk_class Chrome_WidgetWin_1")
WinActivate
wd.ExecuteScript("window.open('https wyagd001.github.io /zh-cn/docs/AutoHotkey.htm')") Broken Link for safety
tabs :=wd.WindowHandles
n := tabs.MaxIndex()
wd.SwitchTo.Window(tabs[n])
wd.FindElementByXPath("//*[@id='head']/div/div[1]/ul/li[2]/button").click()
wd.Quit()[/code]