Enter text in text field without using PressKeys method : Automation API

Enter text in text field without using PressKeys method

Class library usage, coding and language questions.

Enter text in text field without using PressKeys method

Postby akommalapati » Wed Dec 14, 2011 3: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
akommalapati
 
Posts: 21
Joined: Wed Dec 07, 2011 3:54 pm
Location: India

Re: Enter text in text field without using PressKeys method

Postby Support Team » Wed Dec 14, 2011 4: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
User avatar
Support Team
Site Admin
 
Posts: 4841
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Enter text in text field without using PressKeys method

Postby akommalapati » Tue Dec 20, 2011 2: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);

}




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

Re: Enter text in text field without using PressKeys method

Postby sham526 » Tue Dec 20, 2011 2:54 pm

I think

Instead of

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

u just try

if (inputtext.Value == "")
{
inputtext.value=textvalue;
}
sham526
 
Posts: 17
Joined: Wed Jul 07, 2010 8:12 am
Location: Hyderabad(INDIA)

Re: Enter text in text field without using PressKeys method

Postby akommalapati » Thu Dec 22, 2011 8:53 am

Thanks for reply, this solved my problem

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


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests