Visual Basic - Change textarea content - vb.net

I want to change textarea from omeagle.com -> text cheat
The textarea has this code in HTML :
<textarea class="chatmsg " cols="80" rows="3"></textarea>
In visual basic I program my webbrowser1 to navigate to this page. What do I need to do to change the text inside the textarea?
I've already tried this:
WebBrowser1.Document.All.Item("chatmsg").InnerText = "mycontent"
WebBrowser1.Document.All("chatmsg_area").InnerText = "this works"
WebBrowser1.Document.All("chatmsg_body").InnerText = "this works"
More ....

You can not get an element by class name. You can loop through all of the elements and check for a class name though.
Set NodeList = WebBrowser1.Document.getElementsByTagName("*")
For Each Elem in NodeList
If Elem.GetAttribute("class") = "chatmsg " Then
Elem.InnerText = "mycontent"
End If
Next

Give your textarea an id, then access it by its id.
<textarea id="text1"></textarea>
....
WebBrowser1.Document.All("text1").innerText = "New text"

Related

Why HtmlAgilityPack adds some characters to my html

Here is my code:
Dim input = "<div><textarea>something</div></textarea>"
Dim doc As New HtmlAgilityPack.HtmlDocument
doc.OptionOutputAsXml = True
doc.LoadHtml(Input)
Using writer As New StringWriter
doc.Save(writer)
Dim res = writer.ToString
End Using
and the value of 'res' is:
"<?xml version="1.0" encoding="windows-1255"?>
<div>
<textarea>
//<![CDATA[
something
//]]>//
</textarea>
</div>"
the result as html is: My textarea
How can I prevent it ?
From my understanding of it, the reason is implied by this answer to Set textarea value with HtmlAgilityPack:
A <textarea> element doesn't have a value attribute. It's content is it's own text node:
<textarea>
Some content
</textarea>
To simulate the same thing safely, HAP has to enclose the content in a //<![CDATA[ section.
The source code for HAP has this comment for the relevant line(s):
// tags whose content may be anything
ElementsFlags.Add("textarea", HtmlElementFlag.CData);
So, you can't prevent it.

Change textarea inside webbrowser

I'm trying for hours to change a text area inside a webbrowser in VB.net. I was not able to do it... This is the code from that textarea :
<textarea name="message_html" class="textCtrl MessageEditor BbCodeWysiwygEditor " id="ctrl_message_html" style="height: 260px; display: none;" data-options='{"autoSaveFrequency":"60","bbCodes":[]}' data-auto-save-url="forums/Snapchat-Girls/save-draft" data-dialog-url="index.php?editor/dialog&style=1" data-css-url="css.php?style=1&css=editor_contents&d=1447310869"><p>This is where the text will be</p></textarea>
Note : Loog for "This is where the text will be" inside the code.
Codes i tried :
For Each element As HtmlElement In Me.WebBrowser1.Document.All
If element.OuterHtml.Contains("textCtrl MessageEditor") Then
element.SetAttribute("value", "TEST")
End If
Next
WebBrowser1.Document.GetElementById("ctrl_message_html").SetAttribute("value","TEST")
For Each element As HtmlElement In Me.WebBrowser1.Document.All
element.SetAttribute("value", "TEST")
Next
None of these worked...
PS : Is not my website. So don't ask me to add ids or something.
I am sure this is not needed anymore, but for reference to those who might still be looking for an answer to this question....maybe this might help your needs
Dim Wctl as string = WebBrowser1.DocumentText.Replace("[searchvalue1]", "test1").Replace("[searchvalue2]", "test2")
Then
WebBrowser1.DocumentText = "0"
WebBrowser1.Document.OpenNew(True)
WebBrowser1.Document.Write(Wctl)
WebBrowser1.Refresh()

<xe:djextNameTextBox> how to programmatically add a new entry?

I have a name picker attached to the input but also want to allow type-ahead in a second field attached to the name picker, and then add the selected entry in the type-ahead control to the dojo name text box control.
In the typeahead onchange event, I can get the value of it and I can get the values in the Name Text Box control, but each entry in the NameTextBox is a spanned link like this:
<SPAN tabIndex=0 val="**abbreviatedNotesName**"><A class=lotusFilter tabIndex=-1 href="javascript:;">**commonNotesName**<SPAN class=lotusClose>x</SPAN></A></SPAN>
Do I need to re-write the innerHTML of the NameTextBox, and guess at the commonname from the typeahead result? Or, is there a better way? Thanks for any help/suggestions.
Here's the code:
<div id="copyToRow">
<div class="namePickerContainer">
<xe:namePicker id="namePicker1" for="fld_copyto_recipients">
<xe:this.dataProvider>
<xe:namePickerAggregator>
<xe:this.dataProviders>
<xe:dominoNABNamePicker addressBookSel="all"
nameList="peopleAndGroups">
</xe:dominoNABNamePicker>
<xe:dominoViewNamePicker labelColumn="$1"
viewName="($VIMPeople)" databaseName="#{javascript:viewScope.personalNAB;}"
label="#{javascript:viewScope.personalNABTitle;}">
</xe:dominoViewNamePicker>
</xe:this.dataProviders>
</xe:namePickerAggregator>
</xe:this.dataProvider>
</xe:namePicker>
<xp:div id="copyToContainer" styleClass="addresseeContainer">
<xe:djextNameTextBox id="fld_copyto_recipients"
value="#{sendFilesDoc.file_CopyToRecipients}" multipleSeparator=","
style="min-height:1.5em;" multipleTrim="true">
</xe:djextNameTextBox>
<xp:inputTextarea id="copyto_typeahead">
<xp:typeAhead mode="partial" minChars="1"
preventFiltering="true">
<xp:this.valueList><![CDATA[#{javascript:getComponent("namePicker1").getTypeAheadValue(this)}]]></xp:this.valueList>
</xp:typeAhead>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="copyToRow">
<xp:this.script><![CDATA[var copyTo = XSP.getElementById("#{id:copyto_typeahead}");
var result = XSP.getElementById("#{id:copyToTA}");
var newEntry = '<SPAN tabIndex=0 val="' + copyTo.value + '"><A class=lotusFilter tabIndex=-1 href="javascript:;">' + copyTo.value + '<SPAN class=lotusClose>x</SPAN></A></SPAN>';
//Format: <SPAN tabIndex=0 val="<abbreviated NotesName>"><A class=lotusFilter tabIndex=-1 href="javascript:;">common NotesName<SPAN class=lotusClose>x</SPAN></A></SPAN>
result.value = copyTo.value;
var copyToRecipients = XSP.getElementById("#{id:fld_copyto_recipients}");
//<INPUT style="MIN-HEIGHT: 1.5em" id=view:_id1:include1:fld_copyto_recipients type=text name=view:_id1:include1:fld_copyto_recipients dojoType="extlib.dijit.NameTextBox">
var copyToValue = copyToRecipients.innerHTML;
alert('copytorecipients innerHTML = ' + copyToValue);
alert('copytorecipients value = ' + document.getElementById("#{id:fld_copyto_recipients}").value); <-- undefined
var copyToArray = new Array();
var a = document.getElementsByName("#{id:fld_copyto_recipients}");
copyToArray = (a[0].value.split(','));
copyToArray.push(result.value);
//copyToRecipients.value = copyToArray.join(','); <-- this does not work
alert('copyToArray value = ' + copyToArray.join(','));
result.value = copyToArray.join(',');
copyTo.value = "";
return;]]></xp:this.script>
</xp:eventHandler>
</xp:inputTextarea>
</xp:div>
<xp:inputText id="copyToTA">
</xp:inputText>
</div></div>
What I think was tripping me up was required validation on the NameTextBox seemed to prevent the onchange event in the typeahead from firing. Who knows? Went through a lot of iterations ... I ended up adding Tommy Valand's JS function to control when validation is triggered & that seemed to fix things.
Bound the NameTextBox to the datasource field. Bound the typeahead to a requestScope variable. The typeahead onchange event code below also does a partial refresh on a container panel that wraps the 2 inputs.
/* append the typeahead name to those already selected */
var curVals:java.util.Vector = sendFilesDoc.getItemValue("file_SendToRecipients");
curVals.addElement(requestScope.sendToTypeAhead);
sendFilesDoc.replaceItemValue("file_SendToRecipients",curVals);
requestScope.sendToTypeAhead = null;
Then in the NameTextBox onChange event that also partial refreshes the container panel:
/*
remove duplicates that can be picked if the format of the displayed name in the right panel of the
name picker dialog doesn't match the column returned from the picker -- for instance, this will
happen on internet-style names stored in the user's personal names.nsf
e.g. FName LName <user#somecompany.com>
*/
var thisField:javax.faces.component.UIInput = getComponent("fld_sendto_recipients");
var theNames = #Unique(thisField.getValue());
thisField.value = theNames;
So you end up with something similar to how MSN hotmail works. Just have one final issue to try to resolve and that's how to get the cursor to return to the typeahead field after either using the namepicker or making a typeahead choice. Added this code as per this post on the client onchange event of the NameTextBox but the cursor just jumps into the typeahead field but then immediately jumps out:
/* set focus back on the typeahead input -- the input is a child of the typeahead dojo widget */
/* matches any <input> that is a child of the .dijitInputField class of the <div> for the typeahead */
var el = dojo.query('div[widgetid*="sendto_typeahead"] .dijitInputField > input').at(-1)[0].focus();
Any help??? Or, suggestions for solution improvement??

How can I move the selection in dijit editor?

I have a problem with dijit editor of dojo:
I used execCommand to insert html content at the cursor in editor like :
var ed = dijit.byId('myEditor');
var myDiv = "<div id='myDiv'> This is content of div </div>"
ed.focus();
ed.execCommand("inserthtml", myDiv);
myDiv is inserted successfully into the editor, but when I type other content in the editor, that content is within myDiv. So could you tell me how can I move the selection to be after that div ?
Thank you for help !
If you mean you want to place cursor after your inserted div , then try:
var ed = dijit.byId('myEditor');
var myDiv = " This is content of div "
ed.focus();
ed.execCommand("inserthtml", myDiv);
ed.execCommand("inserthtml", "<br />"); //add a break tag after your new div
ed.placeCursorAtEnd(); // places cursor at the end
Did you mean something like this

Use VBA code to click on a button on webpage

I am editing a vba program and want to code the vba to click on a button in a webpage. The html for the button is:
<input type="image" src="/lihtml/test_button3.gif" align="left" alt="File_Certificate_Go"/>
I imagine I would have to set a variable to getElementBy??? and then variable.click, but I can't figure out how exactly to get the element (because it doesn't have a name or id, and I can't give it one because it is not my webpage).
Any help is greatly appreciated!
Perhaps something on the lines of:
Set tags = wb.Document.GetElementsByTagname("Input")
For Each tagx In tags
If tagx.alt = "File_Certificate_Go" Then
tagx.Click
End If
Next
Where wb is the WebBrowser control.
Is there a reason you couldn't give the element an id?
i.e.:
<input id='myButton' type=image src="/lihtml/test_button3.gif" align=left alt=File_Certificate_Go>
then:
document.getElementById('myButton').click()
edit: Based on your comment, you'd have to grab all input elements on the page, and then cycle through them looking for the one that makes your input unique:
var elms = document.getElementsByTagName("input");
for (var i=0; i< elms.length; i++)
if(elms[i].src = '/lihtml/test_button3.gif') { elms[i].click(); }
Something along those lines anyway