通过硒VBA启动chrome或IE [英] launching chrome or IE via selenium VBA

查看:148
本文介绍了通过硒VBA启动chrome或IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个使用Selenium VBA下载Web数据的代码,它在Firefox中效果很好,但是很多时候Firefox崩溃了.我试图从vba启动chrome/IE,但操作不正确.下面是我的代码....请帮助.

I have written a code for web data downloading using selenium VBA, it works good in Firefox, but many time Firefox is crashing. I tried to launch chrome/IE from vba but it's not properly happening. Below is my code....please help.

Public Sub Untitled_2()

  Dim selenium As New SeleniumWrapper.WebDriver
  Dim By As New By, Assert As New Assert, Verify As New Verify, Waiter As New    Waiter

  driver.start "firefox", "https://indexes.nasdaqomx.com/Account/LogOn"

  'below 2 line don't work
  driver.start "ie", "https://indexes.nasdaqomx.com/Account/LogOn"
  driver.start "chrome", "https://indexes.nasdaqomx.com/Account/LogOn"


  selenium.setImplicitWait 10000
  selenium.Type "css=fieldset > div.editor-field > #UserName", "xxxxxxx"
  selenium.Type "css=fieldset > div.editor-field > #Password", "xxxxxxx"
  selenium.clickAndWait "css=fieldset > p > input.button.submit"
  selenium.Click "id=menu-5"
  selenium.Click "id=menu-1"
  selenium.clickAndWait "link=U.S."
  selenium.clickAndWait "id=NDX"
  selenium.clickAndWait "link=Weighting"
  selenium.Click "id=tradeDate"
  selenium.Click "link=20"
  selenium.Select "id=timeOfDay", "label=End of Day"
  selenium.Click "id=update"
  selenium.clickAndWait "id=exportLink"

  selenium.Stop

End Sub

错误截图如下:

如何启动chrome或IE?

How to launch chrome or IE ?

我的chrome驱动程序路径是C:\ Program Files(x86)\ SeleniumWrapper \ chromedriver.exe"

My chrome driver path is C:\Program Files (x86)\SeleniumWrapper\chromedriver.exe"

,即驱动程序路径为C:\ Program Files(x86)\ SeleniumWrapper \ IEDriverServer.exe"

and ie driver path is C:\Program Files (x86)\SeleniumWrapper\IEDriverServer.exe"

推荐答案

我知道您需要 selenium.启动chrome后获取"/" ,因此与IE相同.您还声明了 selenium 作为网络驱动程序,但是随后在代码中使用了 driver ,所以也许尝试以下操作:

I know you need selenium.Get "/" after launching chrome, so it may be the same with IE. You've also declared selenium as a web driver, but then used driver in your code, so maybe try the below instead:

Public Sub Untitled_2()

  Dim selenium As New SeleniumWrapper.WebDriver
  Dim By As New By, Assert As New Assert, Verify As New Verify, Waiter As New    Waiter

  'below 2 line don't work
  selenium.Start "ie", "https://indexes.nasdaqomx.com/Account/LogOn"
  selenium.Get "/"
  selenium.Start "chrome", "https://indexes.nasdaqomx.com/Account/LogOn"
  selenium.Get "/"

  selenium.setImplicitWait 10000
  selenium.Type "css=fieldset > div.editor-field > #UserName", "xxxxxxx"
  selenium.Type "css=fieldset > div.editor-field > #Password", "xxxxxxx"
  selenium.clickAndWait "css=fieldset > p > input.button.submit"
  selenium.Click "id=menu-5"
  selenium.Click "id=menu-1"
  selenium.clickAndWait "link=U.S."
  selenium.clickAndWait "id=NDX"
  selenium.clickAndWait "link=Weighting"
  selenium.Click "id=tradeDate"
  selenium.Click "link=20"
  selenium.Select "id=timeOfDay", "label=End of Day"
  selenium.Click "id=update"
  selenium.clickAndWait "id=exportLink"

  selenium.Stop

End Sub

这篇关于通过硒VBA启动chrome或IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆