-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathset-input-value.js
61 lines (51 loc) · 1.71 KB
/
set-input-value.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Usage:
* In the case when you want to set value to <input> element.
* Use this if Autify is unable to enter values in a test run for some reason.
* <input type="date"> is a typical element that is not supported by Autify.
*
* Change the values written below.
* selector: A string of a selector to pinpoint the element.
* setValue: A value to be set.
*
* 使い方:
* <input> 要素に対して値を設定します。
* 何らかの理由により、Autify のテスト実行で値の入力ができないときにご利用ください。
* <input type="date"> は、Autify が対応していない代表的な要素です。
*
* 以下の値を変更してください
* selector: 対象要素を特定するセレクタの文字列
* setValue: 設定したい値
*/
var selector = "<TODO: REPLACE>";
var setValue = "<TODO: REPLACE>"; /* e.g) var setValue = "2006-01-02" */
/**
* --------- You don't need to touch below ---------------
* --------- ここから下は変える必要はありません ----------
*/
/**
* Locate the element
* 要素を探す
*/
var element = document.querySelector(selector);
/**
* Stop process if it does not exist
* 要素がなければ処理を中断する
*/
if (!element) {
throw new Error('Error: cannot find the element with selector(' + selector + ').');
}
/**
* Set input value
* 値を入力する
*/
changeValue(element, setValue);
function changeValue(input, value) {
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype,
"value"
).set;
nativeInputValueSetter.call(input, value);
var inputEvent = new Event("input", { bubbles: true });
input.dispatchEvent(inputEvent);
}