0
how to interact with existing browser/ opened browser using Selenium webdriver

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

1 Answer

0
Best answer
0

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
                    };
                }
                else
                {
                    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;
                }
            }
            else
            {
                return base.Execute(driverCommandToExecute, parameters);
            }
        }
    }

Hope it helps

answered by
selected by

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.
...