VineGlobal / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
1 stars 0 forks source link

Excel Crash Afte Update #100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Operating system and version (32/64bit) : 64
.Net Framework version : ?
Office name and version(32/64bit) : 2010 64
Browser name and version : Firefox latest
SeleniumWrapper version : Latest

What steps will reproduce the problem with a public website ?
1. Install new version of wrapper for vba
2. Load browser from VBE
3. Excel 2010 crashes

Original issue reported on code.google.com by will...@hyperxmedia.com on 30 Sep 2014 at 5:30

GoogleCodeExporter commented 9 years ago
What error do you get? You can find the description in Control Panel>System and 
Security>Administrative Tools>Event Viewer
Do you have only one version of Excel installed?
Does it crash with the reference added manually to a new workbook or with one 
of the provided workbook?
Does it work with the provided VBS or is it specific to Excel and VBE?

Original comment by florentbr on 3 Oct 2014 at 2:26

GoogleCodeExporter commented 9 years ago
I fixed it by going into my references in VBS and reselecting the Selenium Type 
Library in the browse feature. I am however having an issue when I try to open 
a second browser using the same Web Driver. The second Web Driver throws an 
exception where the first worked perfectly. 

Original comment by will...@hyperxmedia.com on 3 Oct 2014 at 3:47

GoogleCodeExporter commented 9 years ago
I'm aware of this issue. It sometimes happens with workbooks created with the 
previous version.
I suspect that Excel is keeping a temporary compilation of the Workbook.

Regarding the multi-browsing I couldn't reproduce the issue:
Sub testMultiBrowser()
    Dim wd1 As New Webdriver
    wd1.Start "ff", "https://fr.yahoo.com"
    wd1.Open "/"

    Dim wd2 As New Webdriver
    wd2.Start "ff", "https://news.google.co.uk"
    wd2.Open "/"
End Sub

Do you have an example to reproduce it?

Original comment by florentbr on 9 Oct 2014 at 5:46

GoogleCodeExporter commented 9 years ago
This happens when you declare the webdriver as a global variable and try to 
open two different browsers with it. 

Does that make sense?

Dim selenium As New SeleniumWrapper.WebDriver
Dim keys As New SeleniumWrapper.keys
Dim xml1 As String
Dim MyData As DataObject
Dim RescueDate As String
Dim GlobalCurrent As String
Dim TimeToRun
Dim TodayS As String

Sub StartAutoTimeInput()
Call OpenResueProjectEnter

End Sub

Sub OpenRescueProjectEnter()

On Error GoTo x

  TodayS = Format(Date$, "YYYYMMDD")

  TerminateProcess ("firefox.exe")

  selenium.stop
  selenium.Start "firefox", "https://www.rescuetime.com/"
  selenium.setImplicitWait 10000

  selenium.Open "https://www.rescuetime.com/google/login?return_to=%2Fdashboard"
  selenium.Type "id=email", "@hyperxmedia.com"
  selenium.clickAndWait "name=button"
  selenium.Type "id=Email", "William@hyperxmedia.com" GET'S STUCK HERE ON SECOND RUN...
  selenium.Type "id=Passwd", "xxxxxxx" 
  selenium.clickAndWait "id=signIn"

  Call findActiveProjectsToday

  selenium.Open "https://www.rescuetime.com/browse/documents/by/hour/for/the/day/of/" & TodayS & "?project_id=0"

  selenium.SendKeys keys.Control, "t"

  selenium.Open "https://www.rescuetime.com/projects/editor"

  selenium.selectAndWait "id=add_project_id", "label=Stand Up"
  For Each i In FoundProjects
  selenium.selectAndWait "id=add_project_id", "label=" & i

  Next i

x:

Call ActivateChrome

End Sub

Sub ActivateChrome()

On Error GoTo x

  selenium.SendKeys keys.Control, "1"

  Call findActiveProjectsToday

  selenium.SendKeys keys.Control, "2"
  selenium.Open "https://www.rescuetime.com/projects/editor"
  selenium.selectAndWait "id=add_project_id", "label=Stand Up"
  For Each i In FoundProjects
    selenium.selectAndWait "id=add_project_id", "label=" & i
  Next i

  AppActivate "Mozilla Firefox"
  Call ScheduleCopyPriceOver

x:

End Sub

Original comment by will...@hyperxmedia.com on 9 Oct 2014 at 10:30

GoogleCodeExporter commented 9 years ago
I wouldn't recommend to reuse a WebDriver instance after calling "stop" it.
You should declare globally the webdriver variable:
Dim selenium As SeleniumWrapper.Webdriver

and create a new instance for each "start" call in your sub:
If Not selenium Is Nothing Then selenium.stop
Set selenium = New SeleniumWrapper.Webdriver
selenium.Start "firefox", "https://www.rescuetime.com/"

What error do you get and have checked manually that the field with id "Email" 
is present on the page at the second run?

Original comment by florentbr on 10 Oct 2014 at 9:38

GoogleCodeExporter commented 9 years ago
It was doing this before I called stop. I added stop to see if I could get it 
to work again. 

So you recommend declaring the variable within the sub as well as globally?

When I get to email it just says it's thrown a driver exception. Nothing 
specific. 

I want it to open a Firefox browser and then leave it open while I open another 
one to check into more data. 

Original comment by will...@hyperxmedia.com on 10 Oct 2014 at 4:08

GoogleCodeExporter commented 9 years ago
> So you recommend declaring the variable within the sub as well as globally?
I recommend to declare the variable globally, but to instantiate it (New 
keyword) in the Sub just before the start command.

I've been able to reproduce the issue and found out that a bug is making all 
the Selenium 1 commands failing after a second start on the same instance. So a 
workaround would be to use like I wrote previously one instance for each start 
command:

Dim wd As SeleniumWrapper.WebDriver  'Global declaration

Sub init()
  If Not wd Is Nothing Then wd.stop    'Stops the browser if the instance was started
  Set wd = New SeleniumWrapper.WebDriver   'Creates the instance
  wd.start...
End Sub

Or to use two instances:

Dim wd1 As SeleniumWrapper.WebDriver  'Global declaration 1
Dim wd2 As SeleniumWrapper.WebDriver  'Global declaration 2

Sub init()
  Set wd1 = New SeleniumWrapper.WebDriver   'Creates the instance 1
  Set wd2 = New SeleniumWrapper.WebDriver   'Creates the instance 2
  wd1.start...
  wd2.start...
  test wd1
  test wd2
End Sub

Sub test(wd as WebDriver)
  wd.open "..."
  wd.findElementById("...").click
  ....
End Sub

Original comment by florentbr on 14 Oct 2014 at 2:24

GoogleCodeExporter commented 9 years ago
Great. 

The first recommendation actually started working for me when I did this. 

Dim selenium As New SeleniumWrapper.WebDriver 'WEBDRIVER MUST BE SET UP AS 
GLOBAL AND RESET BELOW TO WORK IN TWO SUBS. 
Dim keys As New SeleniumWrapper.keys
Dim xml1 As String
Dim MyData As DataObject
Dim RescueDate As String
Dim GlobalCurrent As String
Dim TimeToRun
Dim TodayS As String

Sub OpenRescueProjectEnter()

On Error GoTo x

  TodayS = Format(Date$, "YYYYMMDD")

  Set selenium = New SeleniumWrapper.Webdriver 'WEBDRIVER MUST BE SET UP AS GLOBAL AND RESET HERE TO WORK. 

  selenium.Start "firefox", "https://www.rescuetime.com/"
  selenium.setImplicitWait 10000

  selenium.Open "https://www.rescuetime.com/google/login?return_to=%2Fdashboard"
  selenium.Type "id=email", "@hyperxmedia.com"
  selenium.clickAndWait "name=button"
  selenium.Type "id=Email", "William@hyperxmedia.com" 
  selenium.Type "id=Passwd", "xxxxxxx" 
  selenium.clickAndWait "id=signIn"

  Call findActiveProjectsToday

  selenium.Open "https://www.rescuetime.com/browse/documents/by/hour/for/the/day/of/" & TodayS & "?project_id=0"

  selenium.SendKeys keys.Control, "t"

  selenium.Open "https://www.rescuetime.com/projects/editor"

  selenium.selectAndWait "id=add_project_id", "label=Stand Up"
  For Each i In FoundProjects
  selenium.selectAndWait "id=add_project_id", "label=" & i

  Next i

x:

Call ActivateChrome

End Sub

Sub ActivateChrome()

On Error GoTo x

  selenium.SendKeys keys.Control, "1"

  Call findActiveProjectsToday

  selenium.SendKeys keys.Control, "2"
  selenium.Open "https://www.rescuetime.com/projects/editor"
  selenium.selectAndWait "id=add_project_id", "label=Stand Up"
  For Each i In FoundProjects
    selenium.selectAndWait "id=add_project_id", "label=" & i
  Next i

  AppActivate "Mozilla Firefox"
  Call ScheduleCopyPriceOver

x:

End Sub

Original comment by will...@hyperxmedia.com on 14 Oct 2014 at 3:38

GoogleCodeExporter commented 9 years ago
Fixed in v1.0.21.1

Original comment by florentbr on 14 Oct 2014 at 5:08