leochabi / selenium-vba

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

Manipulating controls in an already opened web page #47

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system : win 7
.Net Framework version :4.5.50938
Office Version :2010 (14.0.7109.5000) SP2 MSO (14.0.7106.5003)
SeleniumWrapper version : 1.0.17.0

What is your issue ?

I will keep several web pages opened in my computer and under certain condition 
my vba code will pick up one and execute some operations on it (click on 
buttons, fill text box, etc). So, my first question: How can I identify these 
opened web pages in order to pick up the right one? The second question: Is it 
possible to avoid “selenium.Start” in my code, since the web browser is 
already opened? 
Thank you in advance.

Original issue reported on code.google.com by lpo5...@gmail.com on 26 Jan 2014 at 1:29

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
It's not possible to run some new code against an already opened browser, which 
means that avoiding “selenium.Start” is not possible.
So you can either deal with multiple instances of a WebDriver or you can manage 
multiple windows.

==An example with multiple instances:==

Dim driver1 As SeleniumWrapper.WebDriver
Dim driver2 As SeleniumWrapper.WebDriver

Public Sub StartBrowsers()
    driver1 = New SeleniumWrapper.WebDriver
    driver2 = New SeleniumWrapper.WebDriver
    driver1.Start "firefox", "http://uk.news.yahoo.com"
    driver2.Start "firefox", "http://uk.news.yahoo.com"
    driver1.Open "opinion"
    driver2.Open "business"
End Sub

Public Sub StopBrowsers()
    driver1.stop
    driver2.stop
End Sub

Public Sub DoSomethingOnCondition()
    SeleniumWrapper.WebDriver driver
    Select Case InputBox("Select the instance's number or nothing to exit", "")
        Case "1": driver = driver1
        Case "2": driver = driver2
    End Select
    'you script here
    'driver. ...
End Sub

==An example with multiple windows:==

Dim driver As SeleniumWrapper.WebDriver
Dim window1 As String
Dim window2 As String

Public Sub StartBrowser()
    driver = New SeleniumWrapper.WebDriver
    driver.Start "firefox", "http://uk.news.yahoo.com"

    'Saves the first window
    window1 = driver.WindowHandle
    driver.Open "opinion"

    'Gets a second window
    driver.executeScript "window.open();"
    hwnds = driver.WindowHandles
    driver.switchToWindow hwnds(1)
    window2 = driver.WindowHandle
    driver.Open "business"
End Sub

Public Sub StopBrowser()
    driver.stop
End Sub

Public Sub DoSomethingOnCondition()
    Select Case InputBox("Select the window's number or nothing to exit", "")
        Case "1": driver.switchToWindow window1
        Case "2": driver.switchToWindow window2
    End Select
    'you script here
    'driver. ...
End Sub

Original comment by florentbr on 27 Jan 2014 at 12:41

GoogleCodeExporter commented 8 years ago
As you well described what I need is to run a new code against an already 
opened browser. I will continue trying a solution. I hope it exists. Thank you 
very much for your attention.

Original comment by lpo5...@gmail.com on 27 Jan 2014 at 1:07

GoogleCodeExporter commented 8 years ago

Original comment by florentbr on 8 Sep 2014 at 5:40