How to get the maximum allowed character in any text box eg.user name, email address, in selenium webdriver ?
You can find the field and get the maxlength attribute
In the IDE I think it would be something like this to store it in 'x':
<td>storeAttribute</td> <td>//input[@id='identifier']@maxlength</td> <td>x</td>
although I would use css for the identifier, more like:
Note: in terms of how many characters the user is putting in the field - https://stackoverflow.com/a/3166107/631619 shows over a million allowed so finding out by by using a loop might take a long while (due to the need to actually interact with the browser) depending on whether there is a server side limit being enforced - that will require a POST or PUT so you'll need thousands of them
1) maxlength attribute
In HTML you might have a
maxlength attribute on your input tag. In this case you can extract the value with Selenium's
GetAttribute("maxlength") or similar.
2) No maxlength attribute
However, if you still want to use Selenium to figure it out, here's the pseudo-code logic on how to do it:
- Enter a character N times in the input field (use a loop).
- Get the input's value and see if it is N characters long.
- If it is, start at 1. again with N = N+1.
- If it's not, the maximum length is N-1
Edit: it's possible that you could enter 500 characters but the server-side validation is at 100, for example. To test this, you'll need to perform another action (like saving) to see if any validation gets triggered.