How to automate input type="color" in selenium webdriver?

Viewed 1748

enter image description here

Scenario: Choose color, enter other details and save. when I click on the html element color (input type=color) it opens a color picker which is a window pop_up.

<input type="color" class="form-control ng-pristine ng-valid ng-empty ng-touched" style="width: 70%;" ng-model="modalData[0].StrokeColor" placeholder="color" aria-invalid="false">

this is the html element for me.

The default value is null for the element. Without picking the color i cant save this form. i tried using js command to set the value for the element.

document.getElementsByClassName('form-control ng-valid ng-touched ng-not-empty ng-dirty ng-valid-parse')[0].setAttribute('value', '#32CD32')

this changes the value fo the color but has no impact on either the UI or the save.

how can i handle this, i am not good with scite script. any help. Thanks.

2 Answers

For me simply calling .sendKeys('#FF0000') on the web element worked with Selenium 4 + Chrome.

Related