Dictionary <string, object> get_attributes(string xpath) { var ans2av = (Dictionary <string, object>)MainWindow.This.Browser.ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + @" var es = document.__getElementsByXPath('" + xpath + @"'); if(es.length > 1) alert('Found more than 1 element!'); else if(es.length < 1) alert('Found no element!'); var ans2av = {}; var as = es[0].attributes; for (var i = 0; i < as.length; i++) { var c = as[i].value; if(as[i].name == 'class'){ c = c.replace(/\b__highlight\b/,'').trim(); if(!c) continue; } ans2av[as[i].name] = c; } ans2av['" + Route.Output.Field.INNER_HTML + @"'] = es[0].innerHTML; return ans2av; "); return(ans2av); }
void listen_clicks() { MainWindow.This.Browser.ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + CefSharpBrowser.Define__createXPathForElement() + @" if(document.__onElementSelected){ document.__clickedElement = null; return; } document.__onElementSelected = function(event){ try{ if ( event.preventDefault ) event.preventDefault(); if ( event.stopPropagation ) event.stopPropagation(); event.returnValue = false; var target = event.target || event.srcElement; if(document.__clickedElement == target) document.__selectedElement = document.__selectedElement.parentNode; else document.__selectedElement = target; document.__clickedElement = target; var x = document.__createXPathForElement(document.__selectedElement); window.JsMapObject.htmlElementSelected(x); }catch(err){ alert(err.message); } return false; }; document.addEventListener('contextmenu', document.__onElementSelected, false); "); }
public void Click(string xpath) { ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + @" var es = document.__getElementsByXPath('" + xpath + @"'); if(es.length < 1) alert('no element found:' + '" + xpath + @"'); for(var i = 0; i < es.length; i++){ es[i].click(); } "); }
// int get_elements(string xpath) // { // return (int)MainWindow.This.Browser.ExecuteJavaScript( // CefSharpBrowser.Define__getElementsByXPath() + @" //document.__elementCollection = document.__getElementsByXPath('" + xpath + @"'); //return document.__elementCollection.length; // "); // } string get_value(string xpath, string attribute) { return((string)MainWindow.This.Browser.ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + @" var es = document.__getElementsByXPath('" + xpath + @"'); var vs = ''; for(var i = 0; i < es.length; i++){ vs += '\r\n' + " + (attribute == Route.Output.Field.INNER_HTML ? @"es[i].innerText" : @"es[i].getAttribute('" + attribute + @"')") + @"; } return vs; ")); }
public void SetValue(string xpath, string value) { ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + @" var es = document.__getElementsByXPath('" + xpath + @"'); //if(es.length > 1) // alert('Found more than 1 element!'); //if(es.length < 1) // alert('no element found:' + '" + xpath + @"'); for(var i = 0; i < es.length; i++){ var e = es[i]; //while(e && e.tagName != 'INPUT') // e = e.parentNode; //if(e) e.value = '" + value + @"'; } "); }
List <string> get_links(string xpath) { var os = (List <object>)MainWindow.This.Browser.ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + @" var es = document.__getElementsByXPath('" + xpath + @"'); var ls = []; for(var i = 0; i < es.length; i++){ var e = es[i]; while(e && e.tagName != 'A') e = e.parentNode; if(e) ls.push(e.href); } return ls; "); List <string> ls = new List <string>(); if (os != null) { string parent_url = MainWindow.This.Browser.Url; for (int i = 0; i < os.Count; i++) { ls.Add(GetAbsoluteUrl((string)os[i], parent_url)); } } if (Controller.DebugMode) { if (ls.Count > 3) { Log.Main.Warning("While debugging only first 3 links are taken of actual " + ls.Count); ls.RemoveRange(3, ls.Count - 3); } } return(ls); }
public List <string> GetValue(string xpath) { var os = (List <object>)ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + @" var es = document.__getElementsByXPath('" + xpath + @"'); //if(es.length > 1) // alert('Found more than 1 element!'); //if(es.length < 1) // alert('no element found:' + '" + xpath + @"'); var vs = []; for(var i = 0; i < es.length; i++){ vs.push(es[i].value); } return vs; "); List <string> vs = new List <string>(); foreach (string s in os) { vs.Add(s); } return(vs); }
List <string> get_single_element_xpaths(string xpath) { var os = (List <object>)MainWindow.This.Browser.ExecuteJavaScript( CefSharpBrowser.Define__getElementsByXPath() + CefSharpBrowser.Define__createXPathForElement() + @" var es = document.__getElementsByXPath('" + xpath + @"'); var xs = []; for(var i = 0; i < es.length; i++){ xs.push(document.__createXPathForElement(es[i])); } return xs; "); List <string> xs = new List <string>(); if (os != null) { for (int i = 0; i < os.Count; i++) { xs.Add((string)os[i]); } } return(xs); }
public MainWindow() { This = this; InitializeComponent(); Browser = new CefSharpBrowser(browser, "JsMapObject", route); browser.LoadingStateChanged += delegate(object sender, LoadingStateChangedEventArgs e) { route.Dispatcher.BeginInvoke((Action)(() => { route.IsEnabled = !e.IsLoading; })); url.Dispatcher.BeginInvoke((Action)(() => { url.Text = browser.Address; })); }; Dispatcher.ShutdownStarted += delegate(object sender, EventArgs e) { try { DataFieldsWindow.This.Close(); } catch { } try { OutputWindow.This.Close(); } catch { } }; Closing += delegate { browser.Stop(); Application.Current.Shutdown(); }; back.Click += delegate { browser.Back(); }; forward.Click += delegate { browser.Forward(); }; stop.Click += delegate { browser.Stop(); }; reload.Click += delegate { browser.Reload(); }; url.KeyUp += (object sender, KeyEventArgs e) => { if (e.Key == Key.Enter) { browser.Load(url.Text); } }; load_images.Click += set_load_images; load_images.IsChecked = true; set_load_images(null, null); }