Enable or maximize program window

Asked

Viewed 763 times

3

I have a JAVA program that uses Selenium Web Driver to access some pages and print them. I print by simulating the Ctrl+P keys and then Enter.

The problem: There are several pages and several impressions, when you arrive at the next printing may happen that Adobe is late and is open above the browser, which makes it impossible to print by clicking the keys.

The solution: I would like to know how to activate the chromedriver.exe window ( which is the program that remains open ). It can be a JAVA solution that from the exe name or Windows window activate the window. It could be a Selenium command that makes the driver focus. Can be a command in . BAT or . VBS.

Any option will be of great help!

1 answer

3


In VBS it is possible using code:


  • Update: for activate and also maximize the program window

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.AppActivate "chromedriver"
                            'usando sendkey para maximizar janela via teclas ::
objShell.SendKeys ("% ")    'update /teclas: alt==[%]+espaço==[ ] 
WScript.Sleep 000000000999  'update /sleep/timeout > 1 segundo
objShell.SendKeys ("x")     'update /tecla: x (maximizar janela)

To call the code:

"%Windir%\System32\CScript.exe" //nologo "Show_Active.vbs"

Or in a that creates the and monitors whether the Adobe open, if positive, calls the window chromedriver.exe foreground:

@echo off 

>"%temp%\Show_Active.vbs"^
 (
  echo/ Set objShell = WScript.CreateObject^("WScript.Shell"^)
  echo/ objShell.AppActivate "chromedriver"
  echo/
  echo/ objShell.SendKeys ^("%% "^)        'update /para maximizar janela/
  echo/ WScript.Sleep 000000009999         'update /para maximizar janela/
  echo/ objShell.SendKeys ^("x"^)          'update /para maximizar janela/
 )

set _Run_CScript="%Windir%\System32\CScript.exe" //nologo
set _Show_Active=%_Run_CScript% "%temp%\Show_Active.vbs"

:_loop_:

:: para sair do looping quando a aplicação n estiver mais rodando :: 
>nul ( tasklist | find /i "chromedriver" || goto :eof )
>nul ( timeout /t 2 /nobreak >nul & tasklist | find /i "AcroRd32.exe"
) && ( start "" /b %_Show_Active% ) >nul

goto :_loop_:

Obs.: To use a which creates a , it is necessary to use , (like the ^)quando os caracteres are not in quotes:

Example: ^(, ^), ^{, ^}, ^&, ^>, ^<, ^|, etc...

More examples nesse link!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.