本文介绍了如何使输入类型=“颜色"自动化.在硒webdriver?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:选择颜色,输入其他详细信息并保存.当我单击html元素颜色(输入类型=颜色)时,它会打开一个颜色选择器,它是一个窗口pop_up.

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">

这是我的html元素.

this is the html element for me.

该元素的默认值为null.如果不选择颜色,我将无法保存此表格.我尝试使用js命令设置元素的值.

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')

这会更改颜色的值,但对UI或保存都没有影响.

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

我该如何处理,我对scite脚本不满意.任何帮助.谢谢.

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

推荐答案

尝试以下代码

JavascriptExecutor js = (JavascriptExecutor) w;
WebElement ColorElement =w.findElement(By.cssSelector("input[type='color']"));
js.executeScript("arguments[0].setAttribute('value', '#FF0000')",ColorElement);

这篇关于如何使输入类型=“颜色"自动化.在硒webdriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 21:29