Working with textarea - textarea

How can I work with textareas using watin? There is no function like "browser.TextArea(...)".
Is there another name for textareas? I only need to find it and work with rows/cols.

Use the TextField method to access a TextArea.
From the Watin Homepage (modified for this question)
[Test]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
// If there was a TextArea with the name q - the next line would get the TextArea object and assign it to the textField variable.
var textField = browser.TextField(Find.ByName("q"));
// Do what you need to do with the TextArea, for example, get the text from the textArea:
string textAreaText = textField.Value;
}
}

Just came across this myself. I thought I would post a more complete answer for people that are still stumped by this. Just use the GetAttributeValue method on the TextField instance like so:
TextField field = Document.TextField(Find.ByName("comments"));
Assert.AreEqual("10", field.GetAttributeValue("rows"));
Assert.AreEqual("42", field.GetAttributeValue("cols"));

Related

How can a string control be added in a form during run time?

I want to add a string control on a form during run time when a button is clicked.
What I have tried so far:
Created a form
Added run form method
Added runTimeControl_validate form method
Added button on the form
The button has the following code in its clicked method:
void clicked()
{
FormBuildDesign design = Form.design();
FormBuildGroupControl formBuildGroupControl;
FormStringControl c;
FormControlType fC;
;
// c = addGroup.addControl(FormControlType::String, 'RunTimeControl');
c = ButtonGroup.addControl(fC::String, 'test');
c.label("New control");
formBuildGroupControl = formBuildDesign.control(addGroup.id());
}
I am getting error in the line c = ButtonGroup.addControl(fC::String, 'test');
Error: Enumeration doesn't exist
Firstly, replace fC::String with FormControlType::String.
Secondly, string controls cannot be added to button groups (ButtonGroup control type) - add it to a normal Group instead.
Thirdly, to avoid such issues as missing labels, etc., it makes sense to add element.lock(); before adding the control and element.unlock(); after updating its label. - ignore this.

How do I prevent one specific character to be entered into a UITextView (in Xamarin)?

I need to prevent users from entering a caret ("^") into a notes field that is implemented in a UITextView. I found this question: prevent lower case in UITextView, but it's not clear to me when/how often the shouldChangeTextInRange method will be called. Is it called for each keystroke? Is it named this way because it will be called once for a paste? Instead of preventing the entire paste operation, I'd rather strip out the offending carets, which it doesn't look like that method can do.
Our main application (written in C++Builder with VCL components) can filter keystrokes, so that if ^ is pressed, it beeps and the character is not added to the text field. I would like to replicate that behavior here.
Is there any way to do that sanely in Xamarin? I'm doing iOS first, and might be asking about Android later.
Thanks for your help!
Are you using Xamarin.Forms to build your UI? If you're going to be targeting Android, I highly recommend doing so.
If that is the case, then you can easily do this with a custom Entry subclass:
public class FilteredEntry : Entry
{
private string FilterRegex { get; set; }
public FilteredEntry (string filterRegex)
{
// if we received some regex, apply it
if (!String.IsNullOrEmpty (filterRegex)) {
base.TextChanged += EntryTextChanged;
FilterRegex = filterRegex;
}
}
void EntryTextChanged (object sender, TextChangedEventArgs e)
{
string newText = e.NewTextValue;
(sender as Entry).Text = Regex.Replace (newText, FilterRegex, String.Empty);
}
}
Usage:
// The root page of your application
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
Children = {
new FilteredEntry(#"\^")
}
}
};
A typed ^ will be stripped out of the Entry's Text.

How to hide spinner on the basis of text entered in edittext box?

M sorry for wrong English. I want to hide the spinner on the basis of text entered in the edit Text box and not on some click event. This means spinner hiding condition should be checked on the basis of Edit Text value.
Any kind of help will be appreciated.
I have Used TextWatcher class to have a check on the text that is being entered in the edittext. And then have used the method to check ds
private void checkFieldsForEmptyValues()
{
Spinner =(Spinner)findViewById(R.id.site_spinner1);
String s1 = edit1.getText().toString();
String s2 = edit2.getText().toString();
if(s1.equals("admin") && s2.equals("admin"))
{
spinner.setEnabled(false);
}
}

How can i resize a tooltip on moseover() using ActionScript and add more interactive content in it?

I like to make a general module in ActionScript to create an interactive tooltip. The tooltip has to resize on mouseover() event and then should contain hyperlinks once resized. Thanks
Yes, its possible. Are you using Flex? or just pure Actionscript? In the case of actionscript:
Add an event listener to rollOver event, and display the tooltip, heres some code:
[in some function, after the comp is added to the stage ]
public function myComp(){
myComponent.addEventListener(MouseEvent.ROLL_OVER,createToolTip);
stage.addEventListener(MouseEvent.CLICK,destroyToolTip);
}
private var toolTip:CustomToolTip;
private function createToolTip(e:MouseEvent):void{
toolTip = new CustomToolTip();
stage.addChild(myToolTip);
myToolTip.x = e.localX;
myToolTip.y = e.localY;
}
private function destroyToolTip(e:Event):void{
stage.removeChild(toolTip);
toolTip = null;
}
(you might need to refine the tooltip destruction logic, now it gets destroyed, if you click anywhere. For example you could call Event.stopPropagation, if the user click inside the tooltip. )
The custom tooltip class:
package{
class CustomToolTip extends Sprite{
public function CustomToolTip():void{
super();
// put drawing logic, children, text,... here.
}
}
}

Add an event to HTML elements with a specific class

I'm working on a modal window, and I want to make the function as reusable as possible. Said that, I want to set a few anchor tags with a class equals to "modal", and when a particular anchor tag is clicked, get its Id and pass it to a function that will execute another function based on the Id that was passed.
This is what I have so far:
// this gets an array with all the elements that have a class equals to "modal"
var anchorTrigger = document.getElementsByClassName('modal');
Then I tried to set the addEventListener for each item in the array by doing this:
var anchorTotal = anchorTrigger.length;
for(var i = 0; i < anchorTotal ; i++){
anchorTrigger.addEventListener('click', fireModal, false);
}
and then run the last function "fireModal" that will open the modal, like so:
function fireModal(){
//some more code here ...
}
My problem is that in the "for" loop, I get an error saying that anchorTrigger.addEvent ... is not a function.
I can tell that the error might be related to the fact that I'm trying to set up the "addEventListener" to an array as oppose to individual elements, but I don't know what I'm supposed to do.
Any help would be greatly appreciated.
anchorTrigger[i].addEventListener...

Resources