Vba Selenium中按钮点击事件上的PhantomJSDriverTimes
我有Excel中的VBA代码,应该可以登录到网站并使用Selenium下载一些文件。我让我的代码使用Vba Selenium中按钮点击事件上的PhantomJSDriverTimes,vba,excel,selenium,selenium-webdriver,phantomjs,Vba,Excel,Selenium,Selenium Webdriver,Phantomjs,我有Excel中的VBA代码,应该可以登录到网站并使用Selenium下载一些文件。我让我的代码使用ChromeDriver工作,并试图将其修改为使用PhantomJSDriver,以便在程序运行时执行其他操作(运行约45分钟)。问题是,当我尝试让Selenium单击登录按钮时,会出现超时错误: Run-time error '101': WebRequestTimeout: No response from the server within 30000 seconds 有趣的是,在它超
ChromeDriver
工作,并试图将其修改为使用PhantomJSDriver
,以便在程序运行时执行其他操作(运行约45分钟)。问题是,当我尝试让Selenium单击登录按钮时,会出现超时错误:
Run-time error '101':
WebRequestTimeout:
No response from the server within 30000 seconds
有趣的是,在它超时后,我可以使用即时窗口截图,很明显按钮被点击,浏览器进入下一页
Dim D As New PhantomJSDriver
With D
.ExecuteScript ("window.resizeTo(1920,1080)")
.SendKeys MyKeys.Control, "0" 'Set zoom to 100% (causes errors if not 100%)
.Get "LoginPage.com"
.FindElementByName("username").SendKeys "UserName"
.FindElementByXPath("/html/body/div[@class='centreContent']/form[@id='loginForm']/input[@id='passwordDummy']").Click
.FindElementByXPath("/html/body/div[@class='centreContent']/form[@id='loginForm']/input[@id='password']").SendKeys "Password"
.TakeScreenShot.SaveAs "C:\Users\110SidedHexagon\Downloads\Capture.png" '<---Takes screenshot of login screen with uesername and password filled in
.FindElementByName("loginSubmitButton", 0.1).Click '<---Error occurs here
<--Using the immediate window taking a picture after the error breaks code execution shows login was successful-->
End With
Dim D作为新的PhantomJSDriver
与D
.ExecuteScript(“window.resizeTo(19201080)”)
.SendKeys MyKeys.Control,“0”将缩放设置为100%(如果不是100%,则会导致错误)
。获取“LoginPage.com”
.FindElementByName(“用户名”).SendKeys“用户名”
.findelementbypath(“/html/body/div[@class='centreContent']/form[@id='loginForm']/input[@id='passwordDummy'])。单击
.findelementbypath(“/html/body/div[@class='centreContent']/form[@id='loginForm']/input[@id='password'])。SendKeys“password”
.TakeScreenShot.SaveAs“C:\Users\110SidedHexagon\Downloads\Capture.png”表示单击按钮后,新加载的页面不会在30秒内返回完成状态。
这可能是由于页面中的资源已死亡
您可以尝试增加服务器超时时间:
Dim driver As New PhantomJSDriver
driver.Timeouts.Server = 60000 ' 60 seconds
driver.Get "https://..."
driver.FindElementByName("loginSubmitButton").Click
或者,您可以定义加载页面的超时并跳过错误:
Dim driver As New PhantomJSDriver
driver.Timeouts.PageLoad = 20000 ' 20 seconds
driver.Get "https://..."
On Error Resume Next
driver.FindElementByName("loginSubmitButton").Click
On Error Goto 0
要使用上述示例获取最新版本,请执行以下操作: