cancel
Showing results for 
Search instead for 
Did you mean: 

Change Default Web Browser

SOLVED
Highlighted
Contributor

Change Default Web Browser

Has anyone scripted a way to change the default web browser in Windows10 during a test run? I am able to open the Default apps window, but can't access the various browser options by name, only through keyboard strokes (ie [Tab] and [Enter]), which won't work as it seems the order of the browsers can vary from one machine to another.

 

I've been using Object Browser and Spy Tool to try to figure out what I need to add to my project's UI Automation list of accepted windows (at least I think this is what I need to do) but haven't come across the correct combination yet.

 

This is my initial JavaScript function that works, but relies on the browser options being in a specific order:

function TESTsetDefaultBrowser(){

  Sys.Desktop.Keys("[Win]choose a default web browser");
  Sys.Desktop.Keys("[Enter]");
  Aliases.WaitAliasChild("ApplicationFrameHost");
  // select web browser
  Sys.Desktop.Keys("[Enter]");
  Delay(1000);
  // tab to desired browser
  Sys.Desktop.Keys("[Tab][Tab][Enter]");
}

I want to replace the last line with something like Object.ClickItem("Chrome");

 

Here's the Default Apps window in the Object Browser:ObjectBrowser.PNG

 

 

And here's the items I've added to the project's list of UIAutomation accepted windows:UIAutomationList.PNG

 

Any insight is appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

Re: Change Default Web Browser

After much research I came across these two programs to set the default browser programatically for the current user. It seems that it has become a lot less simple than it used to be thanks to a hash that is now a part of the registry editor in recent versions of Windows 10.

 

https://danysys.com/set-file-type-association-default-application-command-line-windows-10-userchoice... 

 

http://kolbi.cz/blog/2017/11/10/setdefaultbrowser-set-the-default-browser-per-user-on-windows-10-and...

 

 

View solution in original post

6 REPLIES 6
Highlighted
Community Hero

Re: Change Default Web Browser

There is likely a commandline way to do this, but my question is what is the end goal for this? Are you testing Windows, or are you testing your application? Why do you need to set the default browser in a Test Complete test?


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Contributor

Re: Change Default Web Browser

I have not been able to find a command line way to do this, so I was hoping someone out there had or had automated this process through the UI successfully.

 

No, I am not testing Windows. My tested desktop app launches web apps (which is what's under test here) to the default browser. Previously, running Windows 7, I had automated the process of changing the default browser through the UI in order to test all supported browsers. Now, with Windows 10, the UI window has changed and this code does not work.

Highlighted
Community Hero

Re: Change Default Web Browser

I haven't tested this personally, but you might try something like this in powershell. 

 

function Set-ChromeAsDefaultBrowser {
    Add-Type -AssemblyName 'System.Windows.Forms'
    Start-Process $env:windir\system32\control.exe -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=google%20chrome'
    Sleep 2
    [System.Windows.Forms.SendKeys]::SendWait("{TAB} {TAB}{TAB} ")
}

 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Contributor

Re: Change Default Web Browser

Thanks, I did try a similar way using a .vbs script based on the responses here: how-to-automate-setting-chrome-as-default-browser-in-windows-10 

But that doesn't actually set the browser for me. It did open the Default apps window, and will open the Email setting but not actually choose anything.

I'm guessing based on the line: 

[System.Windows.Forms.SendKeys]::SendWait("{TAB} {TAB}{TAB} ")

that there is still some UI action going on to get to the web browser settings or the chrome choice? I don't know as I'm not familiar with powershell or vbs scripts, but will keep researching/tinkering with it.

Highlighted
Contributor

Re: Change Default Web Browser

After much research I came across these two programs to set the default browser programatically for the current user. It seems that it has become a lot less simple than it used to be thanks to a hash that is now a part of the registry editor in recent versions of Windows 10.

 

https://danysys.com/set-file-type-association-default-application-command-line-windows-10-userchoice... 

 

http://kolbi.cz/blog/2017/11/10/setdefaultbrowser-set-the-default-browser-per-user-on-windows-10-and...

 

 

View solution in original post

Highlighted
Community Manager

Re: Change Default Web Browser

@mboyce  thank you a lot for digging into this and sharing with us! 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors