问题
I'm Having an issue when running automation tests in Firefox. I'm using selenium webdriver c#. This code runs perfectly on Chrome but when run in Firefox the sendkeys function just doesn't work. Below is the element details:
Tests in Firefox version 58:
<input
id="uiAssessmentsDueDate"
class="form-control ng-pristine ng-valid ng-empty ng-touched"
ng-model="workshop.assessmentsDueDate"
ng-readonly="isReadonly"
tabindex="6"
type="date">
Here is the code I'm using:
Driver.FindElement(By.Id("uiAssessmentsDueDate")).SendKeys("01012018");
I have tried clicking in the box before it I have tried tabbing into the box first then send keys. I have tried everything i can think of. If anyone has a better way to do this or an answer as to why this doesn't work in Firefox it would be much appreciated. If you need anymore info please let me know
回答1:
First thing I noticed - there is a ng-readonly="isReadonly" attribute. Read Only inputs do not allow the user to interact with them, but not sure how it's working in the actual site as I never worked with Angular.
Try, with Selenium, to emulate the user interactions as much as possible. If clicking the input prompts a calendar, use that instead of sending keys.
Something that you may want to check is how the attributes and the field changes when you interact with it (do it with Firefox's console, as it is where it happens), to see if the input you write to is actually that one or when clicked the focus is sent to another one; etc.
来源:https://stackoverflow.com/questions/48500284/firefox-cannot-sendkeys-to-date-picker