Change maxlength based on name="..." Possible? - input

I'll admit, I'm new to this world. Im working on my first site, which has a template file setup. In the template I have a code thats similar to
<input type="text" name="option[**]"/>
Where Option[**] is pulled from somewhere else, heres my issue;
Is there something I can do to limit the text input length based on the option number pulled? I did a
<input maxlength=10 type="text" name="option[**]"/>
and that worked to limit all my text input boxes there to 10, however I have say Option[1] and option[2]; I want 1 limited to 10 and 2 limited to 15. is this possible? remember, Im new to all this :)

Related

How to use scriptAll to grab all values when the intended value is not text type

I have a page with multiple textboxes and dropdowns with values that I am trying to validate. The values in them will be dynamic in each run.
The HTML looks something like:
<input readonly="readonly" class="form-control valid" data-val="true" data="ABC" aria-invalid="false" xpath="1">
What I want to do is grab the value of "data" for each textbox. I have used scriptAll before in such a case when I was grabbing text by using innerText. However, that won't work with a regular value such as in the HTML above.
I did try one solution that worked:
driver.value(//input[#data])
However, that just grabs the first textbox value, is there a way I can combine scriptAll with driver.value? OR would I be better off doing some JS here?
Thank you in advance!
Yes, refer the docs for scriptAll(): https://github.com/karatelabs/karate/tree/master/karate-core#scriptall
Use whatever JS works to get an attribute value. Haven't tried, but this should work, you get the idea:
* def list = scriptAll('input', "_.getAttribute('data')")

Get selected content in a number input when click

I guess is not too much difficult but your help will be useful as always.
I had before a text input where the user if click in it select all the content from this input to be able to replace faster his content like in the next example:
<input type="text" value="whatever" onclick="this.setSelectionRange(0, this.value.length)">
So, my question will be, how can I do the same behaviour in a numeric input like the next one?
<input type="number" value="1111">
I tried to add obviously this onclick="this.setSelectionRange(0, this.value.length)" but seems only to work on the text inputs.
Actually, was easy.
I found this solution that works good.
<input type="number" value="111" onclick="this.select();">

Using repeat.for with bound number

Consider sample below:
//edit.html
<input type="number" step="1" value.bind="number" />
<div repeat.for="num of number">${num}</div>
//edit.ts
export class Edit {
number: number = 2;
}
I expect to see 2 divs on first page load and number of divs should change when I change number in input. Instead I get error
Value for 'number' is non-repeatable
I figured it out. If you bind input field to variable, even when variable is number, it will be changed to string when changed by user. In my case, number became string once changed in input field. I used this gist to help me solve this problem:
https://gist.github.com/jdanyow/d9d8dd9df7be2dd2f59077bad3bfb399
It offers custom element and attribute for binding numbers to input fields.

How to populate a webform variable

I'm attempting to use VB.Net WebBorwser to populate and submit a webform. I'm using webbrowser because I don't know much javascript or c#. I'm open to other ideas of course.
I'm able to populate the form fields easily enough:
m_oWebBrowser1.Document.GetElementById("line1").SetAttribute("value", "Flat 12")
but this isn't enough to trigger the page to set the require variables. I've also tried:
m_oWebBrowser.Document.GetElementById("line1").InvokeMember("change")
and
m_oWebBrowser.Navigate("javascript: PreviousAddress().Address().Line1='Flat 19';")
The input field looks like this:
<input id="previousAddressLine1" class="col-xs-12 col-sm-8" name="previousAddressLine1" tabindex="12" data-bind="value: PreviousAddress().Address().Line1" type="text">
Any help would be great.
-Ben

How to identify in selenium IDE an input followed by a label?

I have to identify a check-box using the label which follows it.
the code is the following:
<input type="checkbox" checked="" value="1" id="email-100-100" name="email-100-100">
<label for="email-100-100" class="firefinder-match">Email me when someone asks me to set a flag</label>
<br>
</td>
I tried
Target://following-sibling::label[text()="Email me when someone asks me to set a flag"]
Target://preceding-sibling::label[text()="Email me when someone asks me to set a flag"]
but in both cases selenium finds the text of label but not the check-box.
Could somebody help me in this?
Thank you in advance
Try
Target://label[text()="Email me when someone asks me to set a flag"]/../input[#type='checkbox']
It will work as long as the containing element of the label and checkbox only has one checkbox in it.
You can also find a label that contains text, which is useful for a partial match. In my case I had something like this:
<label for="blah">
<input name="blah" id="blah" type="checkbox" />
Store Locator Plus
</label>
The accepted solution worked for the specific example cited but requires an exact match. Since this comes up on the top of search results I figured I'd present the partial-match solution here as well.
For Selenium IDE you can set a target like this:
//label[contains(text(),'Store Locator Plus')]//input[#type="checkbox"]
The contains function was required because the label text had an HTML element as well which thwarted the //label[text()='Store Locator Plus'] target.