Could anyone perhaps tell me how should I use the nsIWebBrowserFind interface in GeckoFX to find strings on a webpage?
I tried the following code, but this throws me an ArgumentNullException - parameter cannot be null (pUnk).
I have no idea what this means, I have never used interfaces before.
GeckoWebBrowser browser = getCurrentBrowser();
nsIWebBrowserFind finder = browser.GetInterface<nsIWebBrowserFind>();
finder.SetSearchStringAttribute(searchBox1.Text);
finder.FindNext();
I have also tried
nsIWebBrowserFind finder = Gecko.Xpcom.GetInterface<nsIWebBrowserFind>(browser);
With the same results:(
Please help:)
Thanks!
This works in GeckoFX 29.0:
var field = typeof(GeckoWebBrowser).GetField("WebBrowser", BindingFlags.Instance | BindingFlags.NonPublic);
nsIWebBrowser browser = (nsIWebBrowser)field.GetValue(webBrowser1);
var browserFind = Xpcom.QueryInterface<nsIWebBrowserFind>(browser);
browserFind.SetSearchStringAttribute(search);
try
{
browserFind.SetWrapFindAttribute(true);
browserFind.FindNext();
}
catch { }
Some websites with frames throws an exception after the last result however, this seems to be a bug in GeckoFX. We did a workaround by falling back to a javascript find (javascript:window.find) when the exception was thrown.
Related
I have the following code which is intended to fetch a list of all the user of an organisation.
public static IEnumerable<Member> ListTrelloUsers()
{
var serializer = new ManateeSerializer();
TrelloConfiguration.Serializer = serializer;
TrelloConfiguration.Deserializer = serializer;
TrelloConfiguration.JsonFactory = new ManateeFactory();
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
TrelloAuthorization.Default.AppKey = ApplicationKey;
TrelloAuthorization.Default.UserToken = GrandToken;
var myOrganization = Member.Me.Organizations.FirstOrDefault().Id; //Exception thrown here.
var orgToAddTo = new Organization(myOrganization);
return orgToAddTo.Members.AsEnumerable();
}
But I'm getting a
System.MissingMethodException
thrown on
RestSharp.IRestRequest RestSharp.RestRequest.AddFile(System.String, Byte[], System.String)
So why is this exception thrown and what should the correctly working code look like?
Clarifications
I will also accept working C#/ASP.Net MVC code that isn't based on Manatee.Trello as an answer. (Including pure API-calls.)
I have tried using the Organisation ID directly as
var orgToAddTo = new Organization(OrganisationId);
but that just caused the same exception to be thrown later when I make a call to the method's returned object (e.g. using Count()).
UPDATE: I tried setting the build to Release instead of Debug and now the (same) exception is instead thrown at
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
This is an issue with RestSharp that I reported quite some time ago, though they deny that it's a problem. If you're using .Net 4.5+, you can try the Manatee.Trello.WebApi package instead of Manatee.Trello.RestSharp.
TrelloConfiguration.RestProvider = new WebApiClientProvider();
Here's my Trello card for tracking the issue. This and this are the RestSharp issues I created.
I have been able to recreate this as well, but have received no help from them to resolve it.
Apperently, the class with missing method is located in an assembly, which differ from the one, which you used while compiling the project. Double check and make sure both at compiling and at execution you use the same assembly with the aforementioned class.
That is my best clue based on the info you've provided.
basically, check project references and make sure, you use correct ones for the class-holding assembly.
I'm currently working in c# on universal app for w10, and I'm working with webview.
I'm trying to run script over webview.Invoke()
string functionString = "document.getElementsByName('name').Value = 'jmeno';";
webView1.InvokeScript("eval", new string[] { functionString });
But I'm getting exception: The method or operation is not implemented.
Any ideas, or experiences about this issue?
It looks like your javascript is invalid, though I'm unsure if that'd throw the exception you're seeing.
Specify the index (i.e. [0]) of the element to set the "value" of:
string functionString = "document.getElementsByName('name')[0].value = 'jmeno';";
As the documentation says:
InvokeScript may be altered or unavailable for releases after Windows
8.1. Instead, use InvokeScriptAsync.
So on Windows 10 you should use InvokeScriptAsync.
I've been playing with loading a website (specifically my blog) inside a WebBrowser in WPF. My code is pretty much just one line:
WebBrowser.Source = new Uri("http://www.example.net");
When I run this I get scripting error, like this:
I get similar errors when running other web sites, although not always related to Google Ads.
My assumption is that there is an issue with sites that run JS. Is this correct and, if so, why? Is there a way around it?
The problem here is that the WPF WebBrowser did not implement this property as in the 2.0 control. But with reflection you can get to the activexinstance of the webbrowser control to put the browser in silent mode:
dynamic activeX = this.WB.GetType().InvokeMember("ActiveXInstance",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, this.WB, new object[] { });
activeX.Silent = true;
Is there any way to access the test results (success/fail, maybe even asserts, etc) from a Specflow AfterScenario hook? I don't see anything, but it seems like something that would be included.
You can get hold of the test result by peeking into the ScenarioContext.Current. There's a TestError property that may help you.
See this wiki (https://github.com/techtalk/SpecFlow/wiki/ScenarioContext) for more information.
Yes, there is, but you need to use reflection. In your [AfterScenario] block use the following:
PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("TestStatus", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
object TestResult = getter.Invoke(ScenarioContext.Current, null);
TestResult will be OK, MissingStepDefinition etc.
I use ScenarioContext to do this. Here is some example code which hopefully makes sense (doesn't get the actual assert value - not possible as far as I know), but does mean I can leave the browser open if the test fails:
[AfterScenario]
public void AfterScenario() {
if (ScenarioContext.Current.TestError == null) {
// Test failed (use ScenarioContext.Current.TestError to print out error to logs if required)
_driver.Quit
}
}
I am attempting to implement a Language Service in a VSPackage using the MPF, and it's not working quite as I understand it should.
I have several implementations already, such as ParseSource parsing the input file with a ParseRequest. However, when it finds an error, it adds it with AuthoringSink.AddError. The documentation for this implies it adds it to the Error List for me; it doesn't.
I also have a simple MySource class, a subclass of Source. I return this new class with an overridden LanguageService.CreateSource method. The documentation for OnCommand says it's fired 'when a command is entered'. However, it's not.
There's obviously some intermediate step which I haven't done correctly. I've already rambled enough, so I'll be glad to give any additional details by request.
Any clarification is much appreciated.
For the AuthoringSink error list question, I use this behavior in my Language Service. In ParseSource, the ParseRequest class has an AuthoringSink. You can also create a new ErrorListProvider if you want to work outside of the parser's behavior. Here is some example code:
error_list = new ErrorListProvider(this.Site);
error_list.ProviderName = "MyLanguageService Errors";
error_list.ProviderGuid = new Guid(this.errorlistGUIDstring.);
}
ErrorTask task = new ErrorTask();
task.Document = filename;
task.CanDelete = true;
task.Category = TaskCategory.CodeSense;
task.Column = column;
task.Line = line;
task.Text = message;
task.ErrorCategory = TaskErrorCategory.Error;
task.Navigate += NavigateToParseError;
error_list.Tasks.Add(task);
I hope this was helpful.
OnCommand should be firing every time there is a command, in your MySource class you can do something like this (pulled from working code):
public override void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
{
if (textView == null || this.LanguageService == null
|| !this.LanguageService.Preferences.EnableCodeSense)
return;
if (command == Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.TYPECHAR)
{
if (char.IsLetterOrDigit(ch))
{
//do something cool
}
}
base.OnCommand(textView, command, ch);
}
If that doesn't work double check that CodeSense = true in your ProvideLanguageService attribute when you setup your LanguageService package. A whole lot of what is cool to do in the LanguageService requires these attributes to be correctly turned on. Some even give cool behaviors for free!
Another thing to be careful of is that some behaviors like colorizer don't function correctly in the hive in my experience. I don't think these were ones that gave me trouble, but I implemented these a couple of years ago so I'm mostly just looking back at old code.
AuthoringSink.AddError only adds errors to the error list if ParseRequest.Reason is ParseReason.Check. When your ParseSource function attempts to add errors while parsing for any other ParseReason, nothing will happen.
It's possible that your language service is never calling ParseSource with this ParseReason. As far as I know, the only way to get a ParseReason of Check (outside of manually calling BeginParse or ParseSource yourself) is to proffer your service with an idle timer.