Enter text in text field without using PressKeys method

Class library usage, coding and language questions.
akommalapati
Posts: 21
Joined: Wed Dec 07, 2011 2:54 pm
Location: India

Enter text in text field without using PressKeys method

Post by akommalapati » Wed Dec 14, 2011 2:14 pm

Hi,

Can u please let how i can enter text in a text field(webpage), without using PressKeys method.
I want to use this in the code module. Want to set all text at once in text field.

Thanks
Ajay

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Enter text in text field without using PressKeys method

Post by Support Team » Wed Dec 14, 2011 3:09 pm

Hi,

you can either add new "Set Value" action to your recording by simply drag/drop the specific repository item into the recording and choosing "Set Value" as action. Or if you are working in code you can use following code snippet:
repo.your.InputTag.Element.SetAttributeValue("Value", "yourValue");
Regards,
Tobias
Ranorex Support Team
.
Image

akommalapati
Posts: 21
Joined: Wed Dec 07, 2011 2:54 pm
Location: India

Re: Enter text in text field without using PressKeys method

Post by akommalapati » Tue Dec 20, 2011 1:05 pm

Hi,

I'm unable to work with setattribute method in my code.

Can u please look into my code below and help me with a code snippet.


public void AccessTextBox(string pageName , string textboxName, string textvalue)
{
// Identify a web document by its title
WebDocument TextDocument = "//dom[@caption='" + pageName + "']";
TextDocument.WaitForDocumentLoaded();
Validate.Exists(TextDocument);
TextDocument.WaitForDocumentLoaded();


try
{
IList<Ranorex.InputTag> AllTextTags = TextDocument.FindDescendants<Ranorex.InputTag>();
if(AllTextTags.Count == 0)

foreach(Ranorex.InputTag inputtext in AllTextTags)
{
var TextobjName = inputtext.Name as string;


if (TextobjName != null && TextobjName.ToString() == textboxName )
{

Report.Info("Exists Text Field= " + TextobjName.ToString());

inputtext.Focus();

if (inputtext.Value == "")
{
inputtext.PressKeys(textvalue);
}
else
{
Keyboard.PrepareFocus(inputtext);
Keyboard.Press("{END}{SHIFT DOWN}{HOME}{SHIFT UP}{DELETE}" + textvalue);
}



break;
}
}

}
catch (Exception ex)
{

Report.Error("Error", ex.Message);

}




}

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: Enter text in text field without using PressKeys method

Post by sham526 » Tue Dec 20, 2011 1:54 pm

I think

Instead of

if (inputtext.Value == "")
{
inputtext.PressKeys(textvalue);
}

u just try

if (inputtext.Value == "")
{
inputtext.value=textvalue;
}

akommalapati
Posts: 21
Joined: Wed Dec 07, 2011 2:54 pm
Location: India

Re: Enter text in text field without using PressKeys method

Post by akommalapati » Thu Dec 22, 2011 7:53 am

Thanks for reply, this solved my problem

Ajay