Last active
November 14, 2022 17:17
-
-
Save amaitland/9d354376960b0cd9305a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browser.LoadingStateChanged += OnLoadingStateChanged; | |
//A slightly more complicated example | |
private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args) | |
{ | |
//Wait for the Page to finish loading | |
if (args.IsLoading == false) | |
{ | |
const string script = @"(function() | |
{ | |
var linksArray = new Array(); | |
for (var i = 0; i < document.links.length; i++) | |
{ | |
linksArray[i] = [String(document.links[i].innerHTML), | |
String(document.links[i].innerText), | |
String(document.links[i].href)]; | |
} | |
return linksArray; | |
})();"; | |
browser.EvaluateScriptAsync(script).ContinueWith(x => | |
{ | |
var response = x.Result; | |
if (response.Success && response.Result != null) | |
{ | |
var list = (List<object>)response.Result; | |
//Do something here (To interact with the UI you must call BeginInvoke) | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browser.LoadingStateChanged += OnLoadingStateChanged; | |
//A very basic example | |
private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args) | |
{ | |
//Wait for the Page to finish loading | |
if (args.IsLoading == false) | |
{ | |
//Reccomended to use an anon closure | |
const string script = @"(function() | |
{ | |
return 1 + 1; | |
})();"; | |
browser.EvaluateScriptAsync(script).ContinueWith(x => | |
{ | |
var response = x.Result; | |
if (response.Success && response.Result != null) | |
{ | |
var onePlusOne = (int)response.Result; | |
//Do something here (To interact with the UI you must call BeginInvoke) | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment