mardi 8 décembre 2020

Simulate onchange on input type date in selenium-java (automate date-picker)

I am trying to automate Html date-picker with Selenium using Java. After no working help, I am posting here.
I was able to enter the date value, after some effort with JavascriptExecutor like-

((JavascriptExecutor)driver).executeScript("arguments[0].value=arguments[1]", driver.findElement(By.id("startDate")), "2020-12-10");

But after clicking on the submit button when the entire form object ships to the backend API,
startDate value is missing in that object, btw it shows as an empty string i.e (startDate: " ").
The same happens with endDate element too. All other elements values are populated like numeric, string, email etc.
The date element is described as(<TextInput.> is from react-bootstrap4-form-validation)-

<TextInput type="date" id="startDate" className="form-control date-picker" name="startDate" required={true}
            min={this.state.min} max="2021-12-31" onChange={(e) => this.handleInputChanges(e)} />  

The markup after inspecting element is...(min is current date)

<input class="form-control date-picker" id="startDate" type="date" min="2020-12-09" name="startDate" max="2021-12-31" required="">  

The handleInputChanges() method is implemented as (in ReactJS)

private handleInputChanges = (e: React.FormEvent<HTMLInputElement>) => {
e.preventDefault();
this.setState({
  [e.currentTarget.name]: e.currentTarget.value,
});
};

Note: 1- Should I invoke onchange on WebDriver, if yes how. If no plz suggest something.
2- when the script is running I can see the successful date entry in the respective fields.

Aucun commentaire:

Enregistrer un commentaire