7Gabriel / selenium-vba

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

I want stop firefox when max size its over Task Manager #159

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system and version (32/64bit) : Win 8.1 x64
.Net Framework version : 4.0
Office name and version(32/64bit) : 2015 x64
Browser name and version : firefox (32)
SeleniumWrapper version : 1.0.23.0

What steps will reproduce the problem with a public website ?
1. I open website and use it
Set SeWD_ff = New SeleniumWrapper.WebDriver
SeWD_ff.Start "firefox", "http://uk.news.yahoo.com"
SeWD_ff.setImplicitWait 5000
SeWD_ff.Open "opinion"

2.a moment later
hwnds = SeWD_ff.WindowHandles
for each hnd in hwnds
   if hnd.WorkingSetSize > 250000 then
      hnd.stop
      exit for
   end if
next

So, Where do I read [hwnd.WorkingSetSize]? How?

p/s:I can use code below to Kill Process but not good.
For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from 
Win32_Process Where Name = '" & "firefox.exe" & "'")
   Process.Terminate
Next Process

And if,
            SeWD_ff.WindowHandle = {0a8b6271-5859-47b6-9262-4d75cbfd6751}
Then, 
            GetObject("winmgmts:").get( "Win32_Process.WindowHandle='" & _
                           SeWD_ff.WindowHandle & "'").WorkingSetSize
it do not working.

Answer me as soon as possible, I wait for your letter.

Original issue reported on code.google.com by ntkn88@gmail.com on 2 Jun 2015 at 5:19

GoogleCodeExporter commented 8 years ago
The Selenium API doesn't provide such feature.
The only way to identify the process is to keep track of the last created one.
Here is an example to keep track of the last instance of Firefox:

Sub test()
    GetNewFirefox init:=True 'Stores all the Firefox instances

    Set SeWD_ff = New SeleniumWrapper.WebDriver
    SeWD_ff.Start "firefox", "http://uk.news.yahoo.com"

    Set p= GetNewFirefox()  'Gets the newly created instance
    Debug.Print p.WorkingSetSize   'Displays the working set
    p.Terminate   'Terminates the process
End Sub

Function GetNewFirefox(Optional init As Boolean) As Object
    Static q As String
    If init Then q = "Select * from Win32_Process Where Name='firefox.exe'"
    For Each p In GetObject("winmgmts:").ExecQuery(q)
        q = q & " And ProcessId<>" & p.ProcessId
        Set GetNewFirefox = p
    Next
End Function

Original comment by florentbr on 27 Jun 2015 at 1:40