Cypress - Impossible to type into an input field - input

I am trying to automate a form with Cypress. I managed to get all the input fields except the birth date field.
CSS looks like this:
CSS picture
And my code is:
cy.iframe('#oneid-iframe').find('#InputDOB').type('01011990').should("have.value", "01/01/1990")
Unfortunately Cypress fails to type this value in the field.
Thank you in advance for your help.
Kind regards,

You should look at the devtools to see what's in the DOM.
This problem can happen if the HTML in your screenshot is inside a shadow root, in which case this would be your code
it('tests DOB', {includeShadowDom: true}, () => {
cy.iframe('#oneid-iframe')
.find('#InputDOB')
.type('01011990')
.should("have.value", "01/01/1990")
})
This is just a guess, and the question is why do other input work.
But you should try it in case.

Try this:
cy.get('#oneid-iframe').its('body').find('#InputDOB').click().type('01011990')

Can you try this?
cy.iframe('#oneid-iframe').find('#InputDOB').invoke('removeAttr','type').type('01/01/1990').should("have.value", "01/01/1990");

<label data-testid="InputDOB-wrapper" class="input-text input-DOB displayed" for="InputDOB">
<span data-testid="InputDOB-title" class="field-name">Birth Date</span>
<div data-testid="InputDOB-container" class="input-wrapper field-error"><span class="mask"><span class="birth-date">Birth Date </span>dd/mm/yyyy</span><input type="text" autocapitalize="none" autocomplete="on" autocorrect="off" spellcheck="false" tabindex="0" id="InputDOB" data-testid="InputDOB" inputmode="numeric" aria-label="Birth Date" aria-required="true" aria-invalid="true" aria-describedby="InputDOB-error" value=""></div>
<div class="error-container input-error input-error-text displayed" style="height: 30px;">
<p class="input-error input-error-text displayed" id="InputDOB-error" data-testid="InputDOB-error" role="alert">Your birth date is required.</p>
</div>

Related

Codeception select option

I am using codeception to try and click , selection Option within my the form. The issue is that, when I try to check the checkbox, it selects the privacy info href link, opposed to checkbox which I want it to select.
<div class="row">
<div class="myclass">
<div class="mb">
<label class=" custom-checkbox"><input type="checkbox" id="from_accept" name="fform[accept]" class="custom-checkbox__input" value="1">
<span class="custom-checkbox__text">
::before
"I agree to terms "
terms and conditions
"and some more text here "
privacy info
"."
::after
</span>
</label>
</div>
</div>
</div>
I have tried Xpath & CSS selectors but with no luck, even the hover shows me that it see's just the last href anchor link.
Here is the Answer to your Question:
Try the following xpath:
//div[#class='row']/div[#class='myclass']/div[#class='mb']/label[#class=' custom-checkbox' and #class='custom-checkbox__input']//self::label
Note that there is a blank (i.e. a space) within class=" custom-checkbox"
Let me know if this Answers your Question.

i want to change url parameters

hi my url is something like this abc.domain.com/add/firstname/phone/email which is api link. i want to change parameters first name,phone,email when user enters in form. please let me know if anyone can help. thanks in advance.
add/?Client+Name=&Phone+number=&Email+ID=&Partner+ID=AUOVML i dont want url in this format. format must be as i mentioned in first line. i have done something like this:
<form method="get" action="http://abc.domain.com/add/">
<div class="d-nt-signup">
<div class="d-nt-field-wrap">
<input type="text" label="Name*" id="first_name" name="Client Name" active-color='#FB165B' class="d-nt-login-filed">
</div>
<div class="d-nt-field-wrap">
<input type="text" label="Mobile*" id="mobile" name="Phone number" active-color='#FB165B' class="d-nt-login-filed">
</div>
<div class="d-nt-field-wrap">
<input type="email" label="Email*" id="email ID" name="Email ID" active-color='#FB165B' class="d-nt-login-filed">
</div>
<div class="d-nt-field-wrap">
<input type="hidden" name="Partner ID" value="AUOVML">
</div>
When you do a get request with a form you will get the names and values of the form inputs added to the URL like that.
You can get around that by using a post request instead. Change method="get" to be method="post".
Developers will often handle the result of the form being sent with PHP. Change the action to point to a PHP file, and then in the PHP file you can access the form data through the $_post array like so $_POST["form_input_name"].
See http://php.net/manual/en/tutorial.forms.php for an example of echoing back data typed into a form.

Jasny Bootstrap can't clear the file after submission

I have some html like this:
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="input-group">
<div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div>
<span class="input-group-addon btn btn-default btn-file"><span class="fileinput-new">Select file</span><span class="fileinput-exists">Change</span><input type="file" id="File" name="..."></span>
Remove
</div>
</div>
When the form has been submitted I want to clear the file from the input, but I don't know how to do it.
Jansy says I can do it by calling .fileinput("clear") but that doesn't work.
Has anyone done this before?
If so, how do I clear it?
Cheers
It was being a n00b :)
I was using
$("input[type=file]").fileinput("clear")
but I should have been using
$(".fileinput").fileinput("clear");

<span/> field with HTML enter gives different width/margin than withouth HTML enter

The following code:
<span style="display:inline-block;width:200px;">Selectiedatum</span>
<input type="text" value="30-06-2013" style="width:100px;text-align: right;" />
Gives a different output than:
<span style="display:inline-block;width:200px;">Selectiedatum</span><input type="text" value="30-06-2013" style="width:100px;text-align: right;" />
Yes, the only difference is a HTML enter...
Check http://jsfiddle.net/Et4WZ/
The problem is that this code is created by ASP.net; I can't just simply add or remove a HTML enter.
Why is this occurring and how can I fix it?
Blender was right.
I fixed it by adding a span field with 1 whitespace:
<span> </span>
So:
<span style="display:inline-block;width:200px;">Selectiedatum</span><span> </span><input type="text" value="30-06-2013" style="width:100px;text-align: right;" />

Using attachFile and Submit

I have the following HTML:
<form action="upload" method="post" enctype="multipart/form-data" >
Select a file to upload:
<input type="file" name="file"/>
<input type="hidden" name="USER_NAME" id="USER_NAME" value="user_name"/>
<input type="submit" value="Submit"/>
</form>
I'm having a couple of problems.
Firstly, in the entry field (named "file") I want to set the name of the file to upload. I can do that just with WebElement.type(), but I get a warning about using attachFile. I'm happy to use that, but when I do so I get the error:
com.thoughtworks.selenium.SeleniumException: Element must be user-editable in order to clear it.
My second problem is that if I set the content of the entry field by type(), the submit button doesn't work. I can get the WebElement by css, but neither click() or submit() works. Nothing happens at all when I do either.
Thanks in advance for any help, and apologies for dumbness.