I'm trying to insert some text after the first tag:
<body id="tinymce" spellcheck="false">
<p>
// I want to insert text here
<br>
</p>
</body>
My attempt so far hasn't worked:
IElement tinymice;
string testText = "some text here"
string xPath = string.Format("//body[#id='{0}']/p", "tinymce");
tinymice = GetElementByXPath(xPath);
tinymce.SendKeys(string.Format("{0}", testText ));
Put the text into a span. Paragraph tags are intended to be seperators.
From the docs here: http://jwebunit.sourceforge.net/apidocs/net/sourceforge/jwebunit/api/IElement.html
I infer that you can call:
tinymice.setTextContent("text to insert");
I googled "getelementbyxpath selenium" I hope these are the right docs, it does list selenium at the bottom of the page: http://jwebunit.sourceforge.net/apidocs/net/sourceforge/jwebunit/api/class-use/IElement.html
I realize this is probably a javascript package, but this may be the same methods for the C# dll as well.
I don't think the above person was aware that tinyMCE is tinyMCE and not Tiny Mice..
Related
I'm trying to find a Text via Selenium, which is directly in the HTML.
This can look something like this:
<br>
Uploaded.net
<img class="bbCodeImage LbImage" />
<br>
I found the Image after the Text, but even now, I can't navigate to the text:
I I went to the img-Element, then tried:
var des2 = ele.FindElement(ByProxy.XPath("preceding-sibling::*"));
Interesting enough, this already returns the br-element and not the text, which is right above it. I also tried to brute force it and get all Elements, with this text:
var des2 = thread.FindElements(ByProxy.XPath("descendant::*[contains(text(), \"Uploaded.net\")]")).SelectMany(f => f.FindElements(ByProxy.XPath("descendant::*")));
foreach(var ele in des2)
{
Debug.WriteLine(ele.Text);
}
So I read all Descendants with the mentioned Text and iterate over all of them, but none of them has a Text set.
Am I missing something crucial here?
Selenium doesn't support a text node. You could however get the text with a piece of JavaScript:
string text = (string)((IJavaScriptExecutor)driver).ExecuteScript(
"return arguments[0].previousSibling.textContent.trim();", ele);
I dont think there is any obvious solution to this. Can offer a very very round about solution.
Get the pagesource of the page -- driver.getPageSource();
Split the pagesource by the img tag. Then split the first element of previous split by br tag. The last element of the array should now be the text.
If you have control over development of this, someone should fix the page.
I was wondering if anybody knew how to change the contents of a HTML TextBox with C# I have tried to use body.SetAttribute("value", string) but I did not get anywhere. An example of what I am trying to do is <textarea rows="2" cols="20" id="body" class="messages-reply-box text-box text new-message-body">String I need changed</textarea> Here is what I got so far:
HtmlDocument doc = webBrowser1.Document;
HtmlElement bod = doc.GetElementById("body");
bod.SetAttribute("value", "text");
If you want change the Text of a Element inside your html page you should use InnerText property. This should work
webBrowser1.Document.GetElementById("body").InnerText ="text";
I have a div whose innerHtml is set in my c# code (.cs).
<div id="feedbackRow" runat="server"></div>
.cs
feedbackRow.InnerHtml = "Activate your account to access reward points and unlock deals, discounts and bigger savings!.</br>You will find an ACTIVATE link within the body of the email.If you did not recevied the email into your inbox then please check your spam folders. </br>Thanks again for using ABC";
Here I want to make bold "ACTIVATE" word or say some of the text should be in different color/font in above statement. How do I do that?
You could place the text you want to be bolded between <b> or <strong> tags.
<b>text</b>
or
<strong>text</strong>
maybe simple html:
feedbackRow.InnerHtml = "<strong>Activate</strong> ..."
I am trying to achieve something like this:
string html = #"Hello <b> World ! </b>";
The desired output would be
Hello World !
The string html can be used anywhere on label, textbox, etc.
But it is not working. It just displays as it is Hello <b> World ! </b>
Is there any other way to do this?
Try HtmlString like:
HtmlString html = new HtmlString("Hello <b> World ! </b>");
Use #Html.Raw()
#Html.Raw(string);
See here for more: http://forums.asp.net/t/1903975.aspx?how+to+use+html+raw
Depends on the version of ASP.NET, but your safest bet is to create a literal control
<asp:Literal runat='server' id='yourOutput' Text='' />
And then set it on code behind
yourOutput.Text = html;
This should work on all versions of classic ASP.NET - for MVC projects you already got good answers.
Could someone please advise what the "correct" method is for adding HTML content to an ASP.NET page dynamically?
I am aware of the following declarative method.
//Declaration
<%= MyMethodCall() %>
//And in the code behind.
protected String MyMethodCall()
{
return "Test Value";
}
Is there a better or best practice way?
EDIT: I am building a Galleriffic photo gallery dynamically depending on the images located in a specific folder.
Depends what you want to do.
For controls/text I normally use a LiteralControl and set the Text property as the HTML I want to add, then this control can be added anywhere on the page that you want it to appear
LiteralControl reference is
here
ok seeing as you want it for Galleriffic, I guess it would pseudo-appear as such...
LiteralControl imageGallery = new LiteralControl();
string divStart = #"<div id='thumbs'><ul class='thumbs noscript'>";
imageGallery.Text += divStart;
foreach ([image in images])
{
string imageHTML = #"<li><a class='thumb' name='optionalCustomIdentifier' ref='path/to/slide' title='your image title'>
<img src='path/to/thumbnail' alt='your image title again for graceful degradation' /></a>
<div class='caption'>[caption]<div></li>";
imageGallery.Text += imageHTML;
}
string divEnd = #"</ul></div>";
imageGallery.Text += divEnd;
this.[divOnPage].Controls.Add(imageGallery);
Aspx :
<div id="DIV1" runat="server"></div>
Code behind :
DIV1.InnerHtml = "some text";
There are several ways to do that, which to use really depends on your scenario and preference.
Web User Controls: Can be added dynamically and you get the full editor support of Visual Studio.
XML literals (VB.NET only): Very convenient way to quickly put together HTML in code.
Templates: Add a plain HTML document to your solution and include it as a resource. Then you'll get editor support and you won't clutter your code with HTML source.
Another option
//.aspx
<asp:Literal ID="myText" runat="server"></asp:Literal>
//.aspx.cs
protected Literal myText;
myText.Text = "Hello, World!";