public void CloseTab(ChromeSession session) { var requestUrl = $"{remoteDebuggingUri}/json/close/{session.id}"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUrl); var resp = req.GetResponse(); CurrentSession = null; }
public string GetElementsByTagName(ChromeSession session, string tagName) { // Page.navigate is working from M18 //var json = @"{""method"":""Page.navigate"",""params"":{""url"":""http://www.seznam.cz""},""id"":1}"; // Instead of Page.navigate, we can use document.location var json = @"{""method"":""Runtime.evaluate"",""params"":{""expression"":""document.getElementsByTagName('" + tagName + @"')"",""objectGroup"":""console"",""includeCommandLineAPI"":true,""doNotPauseOnExceptions"":false,""returnByValue"":false},""id"":1}"; return(this.SendCommand(session, json)); }
public string NavigateTo2(ChromeSession session, string uri) { // Page.navigate is working from M18 //var json = @"{""method"":""Page.navigate"",""params"":{""url"":""" + uri + @"""},""id"":1}"; // Instead of Page.navigate, we can use document.location var json = @"{""method"":""Runtime.evaluate"",""params"":{""expression"":""document.location.href='" + uri + @"'"",""objectGroup"":""console"",""includeCommandLineAPI"":true,""doNotPauseOnExceptions"":false,""returnByValue"":false},""id"":1}"; return(this.SendCommand(session, json)); }
public string NavigateTo(ChromeSession session, string uri) { // Page.navigate is working from M18 //var json = @"{""method"":""Page.navigate"",""params"":{""url"":""" + uri + @"""},""id"":1}"; // Instead of Page.navigate, we can use document.location var message = new Message(); message.Params.expression = $"document.location.href='{uri}'"; var json = JsonConvert.SerializeObject(message); return(this.SendCommand(session, json)); }
public string Scroll(ChromeSession session, int distance) { // window.scrollTo(0,0) // window.scrollBy(0,0) // window.pageYOffset // window.pageXOffset var message = new Message(); message.Params.expression = $"window.scrollBy(0, {distance})"; var json = JsonConvert.SerializeObject(message); return(this.SendCommand(session, json)); }
public ChromeSession OpenNewTab(string uri) { var requestUrl = $"{remoteDebuggingUri}/json/new?{uri}"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUrl); var resp = req.GetResponse(); var respStream = resp.GetResponseStream(); StreamReader sr = new StreamReader(respStream); var s = sr.ReadToEnd(); resp.Dispose(); CurrentSession = JsonConvert.DeserializeObject <ChromeSession>(s); return(CurrentSession); }
public string SendCommand(ChromeSession session, string cmd) { return(SendCommand(UpdateEndpoint(session.webSocketDebuggerUrl), cmd)); }
public string Eval(ChromeSession session, string cmd) { var json = @"{""method"":""Runtime.evaluate"",""params"":{""expression"":""" + cmd + @""",""objectGroup"":""console"",""includeCommandLineAPI"":true,""doNotPauseOnExceptions"":false,""returnByValue"":false},""id"":1}"; return(this.SendCommand(session, json)); }