Author Topic: ... and while we're on the subject  (Read 381 times)

stanl

  • Pundit
  • *****
  • Posts: 782
... and while we're on the subject
« on: March 22, 2018, 05:13:18 pm »
[back to Selenium].

When running a Selenium script with ChromeDriver a cmd prompt pops up as the browser is loaded.  I an trying to disable it with this snippet - script does not error but cmd prompt still displays

Code: Winbatch
ObjectClrOption("use", 'WebDriver')
_TRUE = ObjectType( "BOOL", @TRUE )
_FALSE = ObjectType( "BOOL", @FALSE )
objBy = ObjectClrNew('OpenQA.Selenium.By')
oSvc = ObjectClrNew('OpenQA.Selenium.Chrome.ChromeDriverService')
oDefa= oSvc.CreateDefaultService()
oDefa.HideCommandPromptWindow = _TRUE
objDriver = ObjectClrNew('OpenQA.Selenium.Chrome.ChromeDriver')
 

Even the Selenium folks say it is not good practice to hide the command prompt and the hide option was added to appease.  But, I'd like to hide it.

td

  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: ... and while we're on the subject
« Reply #1 on: March 22, 2018, 08:43:24 pm »
Assuming Chrome works like the Firefox driver, you need to pass the service object to the WebDriver object's constructor.  You also need to start the service. Using my previous incomplete example:

Code: Winbatch
objService = ObjectClrNew('OpenQA.Selenium.Firefox.FirefoxDriverService')
objService= objService.CreateDefaultService()
objService.HideCommandPromptWindow = ObjectType("bool", -1)
objService.Start()
objDriver = ObjectClrNew('OpenQA.Selenium.Firefox.FirefoxDriver', objService)
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


stanl

  • Pundit
  • *****
  • Posts: 782
Re: ... and while we're on the subject
« Reply #2 on: March 23, 2018, 02:58:35 am »
Thanks, worked like a charm.