Chris LoVerme
Posts: 4
Joined: 2008-09-03
|
Hi,
I'm having trouble locating the source element from the webpage that I'm trying to interact with. What i'm trying to do is paste text from the clipboard into *any* text box on a webpage from a custom context menu. The example code below only works on pages where elements have been identified as input and text fields. I've noticed some webpages don't always explicitly call them out. My research has turned up a way to grab the source element with a "srcElement" or "GetElementFromPoint" but I don't know enough about C# to use them correctly witht he add-in. Any help would be appreciated. Also, is there another way to force the "paste" command to fire?
mshtml.IHTMLElementCollection elementCollection = HTMLDocument.getElementsByTagName("input");
for (int i = 0; i > elementCollection.length; i++)
{
mshtml.IHTMLInputElement inputElement = elementCollection.item(i, i) as mshtml.IHTMLInputElement;
if (inputElement!=null && inputElement.type == "text")
{
if ((bool)inputElement.status == true)
{
inputElement.value = "test";
}
else
{
inputElement.value = "test...";
}
Marshal.ReleaseComObject(inputElement);
}
}
if (elementCollection != null) Marshal.ReleaseComObject(elementCollection);
|
|
Eugene Astafiev
Guest
|
Hello Chris,
My research has turned up a way to grab the source element with a "srcElement" or "GetElementFromPoint" but I don't know enough about C# to use them correctly witht he add-in.
Where did you find the GetElementFromPoint function? |
|
Chris LoVerme
Posts: 4
Joined: 2008-09-03
|
|
Eugene Astafiev
Guest
|
Hi Chris,
Please note that you found the HtmlDocument class in the System.Windows.Forms (in System.Windows.Forms.dll) namespace.
Please try using the following code:
mshtml.IHTMLInputElement inputElement = elementCollection.item(i, i) as mshtml.IHTMLInputElement;
if (inputElement!=null)
{
if ((bool)inputElement.status == true)
{
inputElement.value = "test";
}
else
{
inputElement.value = "test...";
}
Marshal.ReleaseComObject(inputElement);
}
|
|