How to identify text control by placeholder attribute

Mobile Testing, Android App Testing.
mkeeley
Posts: 2
Joined: Wed Mar 20, 2013 12:10 pm

How to identify text control by placeholder attribute

Post by mkeeley » Wed Mar 20, 2013 12:27 pm

Hi,

I would like to identify a textbox (UITextField in iOS) by its "placeholder" attribute (the greyed out text visible before you enter anything).

I tried setting the XPath to /form/container/text[@placeholder='username'] for example, but it does not find the element.


Also, I could not seem to validate this property either (using an Xpath that works, like text[1]):
Validate.Attribute(repo.DemoRX.SomeContainer.UsernameInfo, "placeholder", "username");
Attribute 'placeholder' of element for item 'DemoRXRepository.DemoRX.SomeContainer.Username' does not match the specified value (actual='(null)', expected='username').

Is there any way of accessing the "placeholder" property? From code?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to identify text control by placeholder attribute

Post by Support Team » Thu Mar 21, 2013 1:46 pm

Hello,

Is there an entry for this property in the repository item?
You can use IntelliSense in order to check if this property is available for this repository item.
repo.DemoRX.SomeContainer.UsernameInfo.Placeholder
If this is the case you can check the value using an if condition.

Regards,
Bernhard

mkeeley
Posts: 2
Joined: Wed Mar 20, 2013 12:10 pm

Re: How to identify text control by placeholder attribute

Post by mkeeley » Fri Mar 22, 2013 9:19 am

It doesn't seem to have this attribute.
My code:

Code: Select all

        	bool found = false;
        	if (repo.DemoRX.SomeContainer.Username.Placeholder == "123")
        		found = true;
        	if (repo.DemoRX.SomeContainer.UsernameInfo.Placeholder == "213")
        		found = true;
Errors:

'Ranorex.Text' does not contain a definition for 'Placeholder' and no extension method 'Placeholder' accepting a first argument of type 'Ranorex.Text' could be found (are you missing a using directive or an assembly reference?) (CS1061)

'Ranorex.Core.Repository.RepoItemInfo' does not contain a definition for 'Placeholder' and no extension method 'Placeholder' accepting a first argument of type 'Ranorex.Core.Repository.RepoItemInfo' could be found (are you missing a using directive or an assembly reference?) (CS1061)


Is there a way of using reflection, or similar method, to access properties not supported by the base Adapter classes?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to identify text control by placeholder attribute

Post by Support Team » Mon Mar 25, 2013 4:13 pm

Hello,

You can also try to use the YourElement.GetAttributeValue("Placeholder") method in order to get the value.
If this will not work please send us a Ranorex Snapshot file in order to analyze the issue in more detail.

Regards,
Bernhard