Changing browserType at run time

Hello,
I have a query. Is the a way to dynamically change the BrowserType property in Attach Browser activity? This will be neat because my clients have different preferences about which browser they use. since the BrowserType property is a dropdown, I have to select one at design time, but after that I cannot change it at run time.
I want to check process status, then change browser type based on which browser process is running on the user’s machine.
I tried to change “app=‘chrome.exe’” or “app=‘firefox.exe’” or “app=‘msedge.exe’”, but because the BrowserType property remains the same, the bot fails.
Why cann’t BrowserType accept a variable, which will make it flexible?

Any suggestion about how to achieve this?

Hi @dari_donkuro,

There are two possible ways of changing browser type the first one will not work on runtime but you have to run the tool before job runs and it is official UiPath software. The second one can be run on runtime, but I would not recommend it because it may be that robot will have to access the file being run and then it would throw an error in runtime. Best to use these before runtime, but if you must then second option is better suited.

  1. Using the new Browser Migration Tool
    This modifies the browser selectors to match the hirearchy of the selectors in both Open browser and Attach browser activities. You can read more about this tool in the release post: UiPath Community 2021.6 Preview Release - News / Release Notes - UiPath Community Forum

  2. Using either UiPath or Powershell to run a script on runtime which changes the Open Browser and Attach Browser text in the .xaml file.

    1. Read the content of an .xaml file (you can also use a folder and get individual .xaml files) and read the text from it.

    2. Editing Browser Type
      ChangedFileContent = System.Text.RegularExpressions.Regex.Replace(FileContents, "BrowserType=([^\s]+)", "BrowserType="+""""+in_RequiredBrowser+"""")

    3. Editing exe
      ChangedFileContent = System.Text.RegularExpressions.Regex.Replace(ChangedFileContent, "app='\w+.exe'", "app="+"'"+in_RequiredAppName.ToLower+".exe'")

    4. Write ChangedFileContent back to an .xaml using Write Text File activity

    Here is a working code for the second approach : ChangeBrowsersType.xaml (11.7 KB)

Again changing attributes / file in runtime may lead to corrupted files so please proceed with caution.

I hope this helps you and others looking for a solution.

1 Like

Hi,
Its available in Uipath 2021.6 community preview version.

2 Likes