Selenium with chrome shows console window of chrome driver , get page complete events

604 views
Skip to first unread message

techw...@gmail.com

unread,
Aug 4, 2014, 3:01:44 AM8/4/14
to seleniu...@googlegroups.com

I am using Selenium for chrome browser automation. I want to open a webpage and fill a login form , submit etc. Below is a part of code

    Dim chromeOptions As New OpenQA.Selenium.Chrome.ChromeOptions()
    chromeOptions.AddExcludedArgument("ignore-certifcate-errors")
    chromeOptions.AddArgument("test-type")
    Dim driver As IWebDriver = New ChromeDriver(chromeOptions)
    driver.Navigate().GoToUrl("https://example.com")


    Dim myLink1 As IWebElement = driver.FindElement(By.Name("userName"))
    myLink1.SendKeys("username")
    Dim myLink2 As IWebElement = driver.FindElement(By.Name("password"))
    myLink2.SendKeys("mypassword")

It works properly. But when i run the application a console window appears when chrome gets open. It is due to chromedriver.exe And cond=sole windows shows "Starting ChromeDriver (v2.9.248315) on port 2078". But I don't want this console window to appear as user suing application will not require it and understand what it is.So is there any way to avoid this console window? Also how can I get page complete events once the page gets loaded completely?

Jim Evans

unread,
Aug 4, 2014, 5:20:24 AM8/4/14
to seleniu...@googlegroups.com
It looks like you're using the .NET language bindings to automate Chrome. The default behavior of displaying the command prompt window is a feature, not a bug. Many people insist on using the .Close() method to exit the browser window instead of .Quit(). However, this would close the browser, but not clean up all resources, like exiting the chromedriver.exe instance. Thus, the .NET bindings maintainer made a conscious decision to make it absolutely clear when the executable is running and when it isn't. You can change this behavior by using code similar to the following:

// assumes your ChromeOptions variable is
// already created
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;

IWebDriver driver = new ChromeDriver(service, options);

techw...@gmail.com

unread,
Aug 4, 2014, 6:38:51 AM8/4/14
to seleniu...@googlegroups.com
How can i get page navigate complete events?When page load completes i should get information about it.Please help

Jim Evans

unread,
Aug 4, 2014, 7:14:42 AM8/4/14
to seleniu...@googlegroups.com
I don't know what that means. Are you asking, "How do I know when a page is completely loaded?" If so, then the answer is, "You don't." Or, more accurately, the question is meaningless when you're talking about today's JavaScript-heavy, AJAX-enabled, dynamically-generated-DOM world.

If you need to make sure an element is present on a page before you can interact with it, you can wait for that condition. The support library (in the WebDriver.Support.dll assembly in .NET) contains a WebDriverWait class designed to enable exactly that.

If you mean something else, you'll need to be more specific in what you're asking.

techw...@gmail.com

unread,
Aug 4, 2014, 7:53:45 AM8/4/14
to seleniu...@googlegroups.com
Ok. I am asking for function similar to document complete. After reading selenium documentation i found that there exists a EventFiringWebDriver which may do what i want(like OnNavigated ) And chromeDriver does not have these. But i didnt get any example of how it(EventFiringWebDriver ) can be used with Onnavigated functions etc. Can u please help?

Jim Evans

unread,
Aug 4, 2014, 11:26:18 AM8/4/14
to seleniu...@googlegroups.com
You could try using the EventFiringWebDriver, which has a Navigated event. You would use standard VB.NET event handling code to hook this up (AddHandler/RemoveHandler). However, **DO NOT** conflate this .NET bindings event with the type of events you receive from Internet Explorer's COM object, like its DocumentComplete event. No such construct exists in the WebDriver API. There is no guarantee whatsoever that any particular DOM event will have fired when the Navigated event is fired. The code to use it would look something like this:

' Assumes you have a sub with a declaration like this: ' Private Sub Navigated(sender As Object, e As WebDriverNavigationEventArgs)
Dim driver As IWebDriver = New ChromeDriver(service, chromeOptions)
Dim eventDriver As New EventFiringWebDriver(driver)
AddHandler eventDriver.Navigated, AddressOf Navigated

Once again, and I cannot stress this enough, if you're looking for an event that means "the page is loaded," You're Doing It Wrong™. You're using an outdated, obsolete, and incorrect paradigm to try to accomplish what you want. The right thing to do is identify some element on the target page that will be present, and wait for that element to be available.

--Jim
Reply all
Reply to author
Forward
0 new messages