0 1
I have a scenario where I need to interact with existing open browser using selenium webdriver in Java.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by
selected by
0 like 0 dislike
Best answer

I've tried this. It works for me.

public class xRemoteWebDriver : RemoteWebDriver
        public static bool newSession;
        public static string capPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", "tmp", "sessionCap");
        public static string sessiodIdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", "tmp", "sessionid");

        public xRemoteWebDriver(Uri remoteAddress)
            : base(remoteAddress, new DesiredCapabilities())

        protected override Response Execute(DriverCommand driverCommandToExecute, Dictionary<string, object> parameters)
            if (driverCommandToExecute == DriverCommand.NewSession)
                if (!newSession)
                    var capText = File.ReadAllText(capPath);
                    var sidText = File.ReadAllText(sessiodIdPath);

                    var cap = JsonConvert.DeserializeObject<Dictionary<string, object>>(capText);
                    return new Response
                        SessionId = sidText,
                        Value = cap
                    var response = base.Execute(driverCommandToExecute, parameters);
                    var dictionary = (Dictionary<string, object>) response.Value;
                    File.WriteAllText(capPath, JsonConvert.SerializeObject(dictionary));
                    File.WriteAllText(sessiodIdPath, response.SessionId);
                    return response;
                return base.Execute(driverCommandToExecute, parameters);

Hope it helps

Related questions