Validating input type number in html5 - validation

I want to restrict entry of input onto a field of type number such that input cannot be outside range of min-max specified in the html.
input type = "number" min = "1" max = "5"
Is there a way of outputting the number field without the text box and i would rather not use
"input type = range"
as slider does not show value currently selected
Please help.
Thanks.

Based on what you said, I suggest using a simple input text field and check it's value validity on submission via JavaScript (as #Kush mentions above). You could also check it as the user types, or moves focus away from that field.

<form>
Only 1 to 100 <input type="text" name="number" pattern="\d{1,2}(?!\d)|100" title="one to hundreed only">
<input type="submit">
</form>

Related

I need to click this input only if it has "aria-checked ="true"

I need to click this input only if it has "aria-checked ="true"
<input class="mat-checkbox-input cdk-visually-hidden" type="checkbox" id="mat-checkbox-131-input" tabindex="0" aria-checked="true" style="" xpath="1">
Ruby:
aria_checked = true
if aria_checked = true
impressora_etiqueta = "//mat-checkbox[#id='mat-checkbox-23']/label/div"
page.find(:xpath, impressora_etiqueta).click
end
There are many ways to do what you want - simplest is probably
page.first('#mat-checkbox-23[aria-checked="true"]', minimum: 0)&.click
which will look for the first element with the given id and aria-checked = "true" and click it if one exists.
Note: the id in your test and sample HTML didn't match so I went the id from your test, adjust as needed. Also you have a class of cdk-visually-hidden shown -- If that's actually making the element not visible on the page, then this won't work and you'll need to add more surrounding HTML to your question with a better description of exactly what you're trying to do (you can't click on non-visible elements)

filter_input behavior for integer input tag name

I have form inputs that have their name attribute in Integer like below
<input type="hidden" name="100351312" value="test" />
If I use
echo filter_input( INPUT_POST, '100351312' )
It returns NULL
Whereas
echo $_POST['100351312'] prints the value correctly.
filter_input really needs three inputs; the type, the variable (both of which you have) and the filter, which you don't have. Here are some types of filters: http://php.net/manual/en/filter.filters.php
That said, if you're using WordPress you can almost always find a WordPress helper function you can use instead of filter_input()

XPATH required for an input text field?

i have a text box in my web application,Where i need to give input. I am trying to find the xpath of the text box. the following error is thrown.
Unable to locate element: {"method":"xpath","selector":"
HTML code:
<div class="input">
<input id="firstName" class="long" type="text" maxlength="50" value="" name="firstName
I want the xpath for firstName textbox.
//input[#type='text']
And this for generally targeting a text input (what I was after)
Try this one:
//input[#id='firstName']
Explanation:
// search on all levels
input for element nodes with the name of "input"
[#id='firstName'] having an attribute (#) with the name of "id" and a value of "firstName"
at least 3 simple ways to get this:
1)Driver.FindElement(By.XPath("//input[#id='firstName']"));
2)Driver.FindElement(By.Id("firstName"));
3)Driver.FindElement(By.CssSelector("#firstName"));
//*[text()[contains(.,'firstName')]]
finding by text would always work.

Scrapy Xpath query to select input tag elements

I'm using Scrapy crawl spider and trying to parse output pages to select all input tag parameter as the following :
input type: must be (text or password or file)
input id: if it's not found , select [input name] instead.
I wrote a sample code for test in Scrapy shell, but it doesn't give me the exact result.
Tested site: http://testaspnet.vulnweb.com/Signup.aspx
>>> hxs.select('//input[#id] | //input[#type="text"] | /text()').extract()
[u'<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTY0MzI4NjU4Mw9kFgICAQ9kFgICAQ9kFgQCAQ8WBB4EaHJlZgUKbG9naW4uYXNweB4JaW5uZXJodG1sBQVsb2dpbmQCAw8WBB8AZB4HVmlzaWJsZWhkZHEZ3VN6SP/C2xESDN/Y3p8zhfSB">',
u'<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWWgKJ+8rsBQLStq24BwK3jsrkBALF97vxAQKozoCcCQKpzpj7DgKSnr/eCQKSnr/eCQKSntPyAgKSntPyAgKSnseJCgKSnseJCgKSnvusAwKSnvusAwKSnu/DDAKSnu/DDAKSnoPmBQKSnoPmBQKSnre9DQKSnre9DQKSnqvQBgKSnqvQBgKSnp+5AwKSnp+5AwKSnrPcDAKSnrPcDAL3pJ3FDwL3pJ3FDwL3pLGYBwL3pLGYBwL3pKU/AvekpT8C96TZ0wkC96TZ0wkC96TN9gIC96TN9gIC96ThjQoC96ThjQoC96SVoAMC96SVoAMC96SJxwwC96SJxwwC96T9rAkC96T9rAkC96SRwwIC96SRwwICyMvj6AUCyMvj6AUCyMuXjw0CyMuXjw0CyMuLogYCyMuLogYCyMu/+Q8CyMu/+Q8CyMvTnQcCyMvTnQcCyMvHMALIy8cwAsjL+9cJAsjL+9cJAsjL7+oCAsjL7+oCAsjLw9MPAsjLw9MPAsjL9/YIAsjL9/YIAq3SwZ8KAq3SwZ8KAq3S9bIDAq3S9bIDAq3S6ckMAq3S6ckMAq3SnewFAq3SnewFAq3SsYMNAq3SsYMNAq3SpaYGAq3SpaYGAq3S2foPAq3S2foPAq3SzZEHAq3SzZEHAq3SofkFAq3SofkFAq3S1Z0NAq3S1Z0NAob5pwUChvmnBQKG+dvZCQKG+dvZCaCOP7DYDQ3mNEhISrmdoTKH9Tws">',
u'<input name="tbUsername" type="text" id="tbUsername" class="Login">',
u'<input name="tbPassword" type="password" id="tbPassword" class="Login">',
u'<input type="submit" name="btnSignup" value="Sign me up" id="btnSignup">']
All input elements of type text, password or file:
//input[#type='text' or #type='password' or #type='file']
I am not sure of what condition you want on the id or name - this will get all input elements of those three types that have either an id or name:
//input[(#type='text' or #type='password' or #type='file') and (#id or #name)]
If you want to test for the id or name (if the id does not exists) equal to something (XXXX):
//input[(#type='text' or #type='password' or #type='file') and (#id='XXXX' or (not(#id) and #name='XXXX'))]
If you want to extract the id:
//input[#type='text' or #type='password' or #type='file']/#id
I don't think extracing either the id or the name if the id is not specified is possible with standard XPaths.
I don't know Scrapy, but from a purely XPath point of view, the following should satisfy the requirements you describe:
//input[(#id or #name) and (#type = 'text' or #type = 'password' or #type = 'file')]
Also, I notice you're trying to retrieve the text content of the selected nodes. This will presumably return nothing because inputs are self-closing tags and do not hold inner content.

what does this xpath expression mean?

//input[#type="hidden" and #name="val" and position() = 1]/#value
does this mean get the text typed inside the input box ?
Read from right to left, it means "Get the value attribute of all of the input tags whose type attribute is 'hidden', whose name attribute is 'val', and which appears as the first element in its enclosing (form) tag".
I think it means grab the value attribute of an input whose type attribute is 'hidden' in addition its name attribute is 'val' and its position amongst its siblings is 1 ( first I believe, not sure if 0 is the start in xpath ).
<input type="hidden" name="val" value="test">
<input type="hidden" name="foo">

Resources