I am writing a tool in C# which has WebBrowser in it and it uses IE 8. Now I want to write a java script which I can run on the webpage inside the WebBrowser to get some elements.
As document.evaluate does not work on Internet Explorer, is there any other way I can achieve it? I have seen some other similar posts however they are related to writing the javascripts directly into HTML using some libraries. I am new to all this so can someone please tell me is there any way I can achieve this through the C# code?
Problem solved. Google's Wicked-good-xpath library worked.
https://code.google.com/p/wicked-good-xpath/
So to explain it, as its a webbrowser control, we need to add js file contents in the script tag of the current html in the WebBrowser and then call the install method as explained in your script.
In case if you are shipping your javascript, then you may need to include the wicked-good-xpath libraries file contents or as per standard way ship the library with your script and add its reference in your code. (In my case I was supposed to send only one js file so added the library contents in the same file)
Thanks minitech for the pointers.!
Related
When I am actually interacting with IE through a .aspx file. I can refer to the defautl xslt as res://msxml.dll/defaultss.xsl.
Dim objDefaultXSL As New System.Xml.XmlDocument
objDefaultXSL.load("res://msxml.dll/defaultss.xsl")
But if I am not using IE which url should i use to to accomplish the same?
Thanks
When i am actually interacting with IE through a .aspx file
I have no idea what you mean with this. ASPX is used server-side to dynamcially create HTML or other pages and serve them with a web server to the client side. The client side can be Internet Explorer, but the ASPX code does not "interact" with the client.
but if I am not using IE which url should i use to to accomplish the same? Thanks
res://msxml.dll/defaultss.xsl is a location in a resource inside a DLL, in this case msxml.dll. This is a Microsoft-specific DLL, used when people in Internet Explorer use XML or XSLT technologies.
When you are not targeting IE, this DLL will not be loaded and so you cannot access that file. But if, for some reason, you want that resource, simply load and save it to disk once and reuse it in your other code. Whether this makes any sense, I doubt it, because that file is specifically meant for IE.
Alright so this may be a total n00b question but I'm using the WatiN 2.1 library with Visual Studio 2013 and I'm trying to automate a mostly javascript-based webpage. I've done this task already using VBA but I wanted to redo it in C#. The webpage has multiple AND elements and some necessary fields are contained in lower levels of each. In VBA, I was able to navigate the page by simple doing something like this:
ie.Document.frames("frameID1").Document.frames("frameID2").Document.getElementByID("target").Click
This line of code would work whether frameID1 or frameID2 were frames or iframes. It didn't seem to matter to VBA. I tried a similar approach in C# using WatiN but it seems like the Frame feature in WatiN only recognizes as frame elements and simply recognizes a element as a simple HTML element.
That being said, I have read the question regarding this found here
but this is where my questoin arises. They say the solution is to alter the code for the AllFramesProcessor method and that fixes it. But how exactly do you access and modify this code? This code is contained in a .dll which I've tried to modify using .NET Reflector. I've export the source code, opened it in Visual Studio, found the code to modify and did so, but when I tried to build a new release, it threw multiple errors. Any suggestions on how to modify this block of code properly and get a version of WatiN that can handle elements?
I have an ASP.NET website that is a panel for managing and sending e-mails. I want people to have an editor to changed what is in the template itself (which is writing in plain HTML.) in withing my site.
But, I don't want them to see the HTML. I just need them to edit the text and not touch the CSS/HTML to not destroy the look of it. Any tips or solutions that any one may know?
Use a free RichTextBox control in your project. You can find many open source or free controls out there.
Here's an example
http://www.freetextbox.com/
In this website you could find a list of controls that you could use.
You can use Ajax "HTMLEditior" or "HTMLEditiorExtender" for this
purpose
For what is HTMLEditor and how to use it follow this link
HTML Editor (AJAX Tool Kit)
Check ckeditor which has lot of editing features and your users can do almost everything. Also it supports inline editing.
I have a batch of HTML files which need some editions easy to perform with jQuery (mainly selecting some nodes and changing their attributes).
My approach to achive this, has been opening them one by one in Google Chrome, excecuting the jQuery code in the console, and then copying the resulting DOM back to my HTML editor.
Since what I'm currently doing takes a lot of time, and also due to the fact that every file needs the same edition (i.e., the same jQuery/JS code will work for every HTML file), I am considering to write a script/program to do this.
Anyway, I am not completely clear of which of the following (if any of them) approaches I should take to accomplish this task.
Write a JavaScript script with jQuery using some FileSystem/File manipulation library (which one?)
Write a Java or C# program using some jQuery-based library (like CsQuery)
Finding a plugin for some of my editors (Aptana, Notepad++, Eclipse, etc) or a completely different editor that supports jQuery-like commands for edition (just as notepad++ regex replacement support). This would be slow with big batches, but at least it would allow me to avoid the annoying copy/paste to/from Chrome.
Is one of this approaches the right way to accomplish what I need? (Is there a right way to do this?) Which should be more straight-forward?
I think that #2 would be easier for me since I have a lot more experience in Java and C# than in JavaScript, but I think that maybe that idea would be sort of using a sledgehammer to crack a nut.
You should consider using PhantomJs. It is a headless WebKit which can be executed from te commandline. It accepts a javascript or coffeescript file as a an argument, which can be used to e.g. do something with a web page. Here is an example:
var page = require('webpage').create();
page.open('http://m.bing.com', function(status) {
var title = page.evaluate(function(s) {
return document.querySelector(s).innerText;
}, 'title');
console.log(title);
phantom.exit();
});
I am not sure of the right way but it sounds like you are familiar with C# and would think writing a class library would be the least overhead for automation. Here are some potential solutions:
Scripting Library (e.g., C#.NET) - You can use a library like the one you mentioned or something like ScriptSharp if you want to use DOM manipulation. If the HTML has appropriate closing tags you can also use LINQ to easily navigate the HTML (or something like the HTML Agility Pack found on CodePlex). I would even recommend using Mustache with an HTML file template in C#.
JavaScript Library - If you wanted to stay in pure JavaScript you can use Node.js. There are file manipulation libraries you can use.
Headless Browsers - Haven't thought through being able to save the resulting HTML automatically but you can use something like jsTestDriver or Phantom.js
You can go with the plugins in editors as well, but I would stick with a Java, C#, python, etc. library that you can potentially call from existing application or schedule as a job/service.
I would like to use a java model. This is model of a human body. It has been written in Java, but I have to use it in ASP.NET. How can I do this? I tried the IKVM open source program. When I created a .dll I got a lot of not found warning. I have already installed the java sdk, and the eclipse. I could run java method under .NET. But I need a full model. Any idea?
Perhaps, - Could you please describe your setup in more detail?
What i gather from your question is that you have an ordinary ASPX page. In this page you would like to host a Java applet.
One suggestion could be to show the applet in an iFrame (read: no need for special DLL's).
In this case you could make a seperate HTML page embed the Applet as usual (:there are tons of howtos out there). And show it in the iFrame.
With this setup you might run in to issues with cross-side scripting, to fix this make sure that the host HTML page is loacted in the same domain as the ASPX page.
Good luck