How to use val method in Puppeteer

Best JavaScript code snippet using puppeteer

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

index.js

Source: index.js Github

copy
1// @flow
2import {
3  isArguments as loIsArguments,
4  isArray as loIsArray,
5  isArrayBuffer as loIsArrayBuffer,
6  isArrayLike as loIsArrayLike,
7  isArrayLikeObject as loIsArrayLikeObject,
8  isBoolean as loIsBoolean,
9  isBuffer as loIsBuffer,
10  isDate as loIsDate,
11  isElement as loIsElement,
12  isEmpty as loIsEmpty,
13  isEqual as loIsEqual,
14  isEqualWith as loIsEqualWith,
15  isError as loIsError,
16  isFinite as loIsFinite,
17  isFunction as loIsFunction,
18  isInteger as loIsInteger,
19  isLength as loIsLength,
20  isMap as loIsMap,
21  isMatch as loIsMatch,
22  isMatchWith as loIsMatchWith,
23  isNaN as loIsNaN,
24  isNative as loIsNative,
25  isNil as loIsNil,
26  isNull as loIsNull,
27  isNumber as loIsNumber,
28  isObject as loIsObject,
29  isObjectLike as loIsObjectLike,
30  isPlainObject as loIsPlainObject,
31  isRegExp as loIsRegExp,
32  isSafeInteger as loIsSafeInteger,
33  isSet as loIsSet,
34  isString as loIsString,
35  isSymbol as loIsSymbol,
36  isTypedArray as loIsTypedArray,
37  isUndefined as loIsUndefined,
38  isWeakMap as loIsWeakMap,
39  isWeakSet as loIsWeakSet,
40} from 'lodash';
41
42
43/**
44 * flow-is-helpers 🠲 Type of helpers
45 * @note 🠲 Pure functions only (no deps)
46 * @note 🠲 Used in-place of lodash for flow %checks till flow-type is fixed
47 * @order
48 *   + Array Helpers
49 *   + Function Helpers
50 *   + Nill Helpers
51 *   + Number Helpers
52 *   + Object helpers
53 *   + String helpers
54 *   + No-Category Helpers
55 */
56
57export const isArguments = (val: any): boolean %checks => loIsArguments(val);
58export const isArray = (val: any): boolean %checks => loIsArray(val);
59export const isArrayBuffer = (val: any): boolean %checks => loIsArrayBuffer(val);
60export const isArrayLike = (val: any): boolean %checks => loIsArrayLike(val);
61export const isArrayLikeObject = (val: any): boolean %checks => loIsArrayLikeObject(val);
62export const isBoolean = (val: any): boolean %checks => loIsBoolean(val);
63export const isBuffer = (val: any): boolean %checks => loIsBuffer(val);
64export const isDate = (val: any): boolean %checks => loIsDate(val);
65export const isElement = (val: any): boolean %checks => loIsElement(val);
66export const isEmpty = (val: any): boolean %checks => loIsEmpty(val);
67export const isEqual = (val: any): boolean %checks => loIsEqual(val);
68export const isEqualWith = (val: any): boolean %checks => loIsEqualWith(val);
69export const isError = (val: any): boolean %checks => loIsError(val);
70export const isFinite = (val: any): boolean %checks => loIsFinite(val);
71export const isFunction = (val: any): boolean %checks => loIsFunction(val);
72export const isInteger = (val: any): boolean %checks => loIsInteger(val);
73export const isLength = (val: any): boolean %checks => loIsLength(val);
74export const isMap = (val: any): boolean %checks => loIsMap(val);
75export const isMatch = (val: any): boolean %checks => loIsMatch(val);
76export const isMatchWith = (val: any): boolean %checks => loIsMatchWith(val);
77export const isNaN = (val: any): boolean %checks => loIsNaN(val);
78export const isNative = (val: any): boolean %checks => loIsNative(val);
79export const isNil = (val: any): boolean %checks => loIsNil(val);
80export const isNull = (val: any): boolean %checks => loIsNull(val);
81export const isNumber = (val: any): boolean %checks => loIsNumber(val);
82export const isObject = (val: any): boolean %checks => loIsObject(val);
83export const isObjectLike = (val: any): boolean %checks => loIsObjectLike(val);
84export const isPlainObject = (val: any): boolean %checks => loIsPlainObject(val);
85export const isRegExp = (val: any): boolean %checks => loIsRegExp(val);
86export const isSafeInteger = (val: any): boolean %checks => loIsSafeInteger(val);
87export const isSet = (val: any): boolean %checks => loIsSet(val);
88export const isString = (val: any): boolean %checks => loIsString(val);
89export const isSymbol = (val: any): boolean %checks => loIsSymbol(val);
90export const isTypedArray = (val: any): boolean %checks => loIsTypedArray(val);
91export const isUndefined = (val: any): boolean %checks => loIsUndefined(val);
92export const isWeakMap = (val: any): boolean %checks => loIsWeakMap(val);
93export const isWeakSet = (val: any): boolean %checks => loIsWeakSet(val);
94
95
96/**
97 * Private Helpers
98 */
99// $FlowFix
100const _getPrototypeName = (val: any): boolean %checks => {
101  const proto = Object.getPrototypeOf(val);
102  return proto && proto.constructor && proto.constructor.name;
103};
104
105
106/**
107 * Array Helpers
108 */
109export const isEmptyArray = (val: any): boolean %checks =>
110  !!val && val.constructor === Array && val.length === 0;
111export const isNonEmptyArray = (val: any): boolean %checks =>
112  !!val && val.constructor === Array && val.length !== 0;
113
114
115/**
116 * Function Helpers
117 */
118export const isPromise = (val: any): boolean %checks =>
119  !!val && (typeof val === 'object' || typeof val === 'function') && typeof val.then === 'function';
120// async fn
121export const isAsync = (val: any): boolean %checks =>
122  _getPrototypeName(val) === 'AsyncFunction';
123// generator iter
124export const isGenerator = (val: any): boolean %checks =>
125  typeof val.next === 'function' && typeof val.throw === 'function';
126// generator fn
127// $FlowFix -> not "supposed" to be as complicated
128export const isGeneratorFunction = (val: any): boolean %checks => {
129  const constructor = val && val.constructor;
130  if (!constructor) {
131    return false;
132  }else if (constructor.name === 'GeneratorFunction' || constructor.displayName === 'GeneratorFunction') {
133    return true;
134  }
135  return isGenerator(constructor.prototype);
136};
137
138
139/**
140 * Nill Helpers
141 */
142export const isNotNil = (val: any): boolean %checks =>
143  val !== undefined && val !== null;
144
145
146/**
147 * Number Helpers
148 */
149export const neginf = Number.NEGATIVE_INFINITY;
150export const posinf = Number.POSITIVE_INFINITY;
151// is not a number
152export const isNan = (val: any): boolean %checks =>
153  typeof val === 'number' && Number.isNaN(val);
154// is infinity
155export const isInfinity = (val: any): boolean %checks =>
156  val === neginf || val === posinf;
157
158
159/**
160 * Object helpers
161 */
162export const isEmptyObject = (val: any): boolean %checks =>
163  isPlainObject(val) &&  Object.keys(val).length === 0;
164export const isNonEmptyObject = (val: any): boolean %checks =>
165  isPlainObject(val) &&  Object.keys(val).length > 0;
166export const isFrozen = (val: any): boolean %checks =>
167  isPlainObject(val) && Object.isFrozen(val);
168export const isSealed = (val: any): boolean %checks =>
169  isPlainObject(val) && Object.isSealed(val);
170export const isExtensible = (val: any): boolean %checks =>
171  isPlainObject(val) && Object.isExtensible(val);
172
173
174/**
175 * String helpers
176 */
177export const isEmptyString = (val: any): boolean %checks =>
178  typeof val === 'string' && val === '';
179export const isNonEmptyString = (val: any): boolean %checks =>
180  typeof val === 'string' && val !== '';
181
182
183
184/**
185 * No-Category Helpers
186 */
187export const isIterable = (val: any): boolean %checks =>
188  isNotNil(val) && typeof val[Symbol.iterator] === 'function';
189// redux
190export const isAction = (val: any): boolean %checks =>
191  val && (typeof val) === 'object' && (typeof val.type) === 'string';
192
Full Screen

taggenerator.js

Source: taggenerator.js Github

copy
1(function($) {
2
3	$.fn.tagGenerator = function(title, options) {
4		var menu = $('<div class="tag-generator"></div>');
5
6		var selector = $('<span>' + title + '</span>');
7
8		selector.css({
9			border: '1px solid #ddd',
10			padding: '2px 4px',
11			background: '#fff url(' + options.fadebuttImageUrl + ') repeat-x 0 0',
12			'-moz-border-radius': '3px',
13			'-khtml-border-radius': '3px',
14			'-webkit-border-radius': '3px',
15			'border-radius': '3px'
16		});
17
18		selector.mouseover(function() {
19			$(this).css({ 'border-color': '#bbb' });
20		});
21		selector.mouseout(function() {
22			$(this).css({ 'border-color': '#ddd' });
23		});
24		selector.mousedown(function() {
25			$(this).css({ background: '#ddd' });
26		});
27		selector.mouseup(function() {
28			$(this).css({
29				background: '#fff url(' + options.fadebuttImageUrl + ') repeat-x 0 0'
30			});
31		});
32		selector.click(function() {
33			dropdown.slideDown('fast');
34			return false;
35		});
36		$('body').click(function() {
37			dropdown.hide();
38		});
39
40		if (options.dropdownIconUrl) {
41			var dropdown_icon = $('<img src="' + options.dropdownIconUrl + '" />');
42			dropdown_icon.css({ 'vertical-align': 'bottom' });
43			selector.append(dropdown_icon);
44		}
45
46		menu.append(selector);
47
48		var pane = $('<div class="tg-pane"></div>');
49		pane.hide();
50		menu.append(pane);
51
52		var dropdown = $('<div class="tg-dropdown"></div>');
53		dropdown.hide();
54		menu.append(dropdown);
55
56		$.each($.tgPanes, function(i, n) {
57			var submenu = $('<div>' + $.tgPanes[i].title + '</div>');
58			submenu.css({
59				margin: 0,
60				padding: '0 4px',
61				'line-height': '180%',
62				background: '#fff'
63			});
64			submenu.mouseover(function() {
65				$(this).css({ background: '#d4f2f2' });
66			});
67			submenu.mouseout(function() {
68				$(this).css({ background: '#fff' });
69			});
70			submenu.click(function() {
71				dropdown.hide();
72				pane.hide();
73				pane.empty();
74				$.tgPane(pane, i);
75				pane.slideDown('fast');
76				return false;
77			});
78			dropdown.append(submenu);
79		});
80
81		this.append(menu);
82	};
83
84	$.tgPane = function(pane, tagType) {
85		var closeButtonDiv = $('<div></div>');
86		closeButtonDiv.css({ float: 'right' });
87
88		var closeButton = $('<span class="tg-closebutton">&#215;</span>');
89		closeButton.click(function() {
90			pane.slideUp('fast').empty();
91		});
92		closeButtonDiv.append(closeButton);
93
94		pane.append(closeButtonDiv);
95
96		var paneTitle = $('<div class="tg-panetitle">' + $.tgPanes[tagType].title + '</div>');
97		pane.append(paneTitle);
98
99		pane.append($('#' + $.tgPanes[tagType].content).clone().contents());
100
101		pane.find(':checkbox.exclusive').change(function() {
102			if ($(this).is(':checked'))
103				$(this).siblings(':checkbox.exclusive').removeAttr('checked');
104		});
105
106		if ($.isFunction($.tgPanes[tagType].change))
107			$.tgPanes[tagType].change(pane, tagType);
108		else
109			$.tgCreateTag(pane, tagType);
110
111		pane.find(':input').change(function() {
112			if ($.isFunction($.tgPanes[tagType].change))
113				$.tgPanes[tagType].change(pane, tagType);
114			else
115				$.tgCreateTag(pane, tagType);
116		});
117	}
118
119	$.tgCreateTag = function(pane, tagType) {
120		pane.find('input[name="name"]').each(function(i) {
121			var val = $(this).val();
122			val = val.replace(/[^0-9a-zA-Z:._-]/g, '').replace(/^[^a-zA-Z]+/, '');
123			if ('' == val) {
124				var rand = Math.floor(Math.random() * 1000);
125				val = tagType + '-' + rand;
126			}
127			$(this).val(val);
128		});
129
130		pane.find(':input.numeric').each(function(i) {
131			var val = $(this).val();
132			val = val.replace(/[^0-9.-]/g, '');
133			$(this).val(val);
134		});
135
136		pane.find(':input.idvalue').each(function(i) {
137			var val = $(this).val();
138			val = val.replace(/[^-0-9a-zA-Z_]/g, '');
139			$(this).val(val);
140		});
141
142		pane.find(':input.classvalue').each(function(i) {
143			var val = $(this).val();
144			val = $.map(val.split(' '), function(n) {
145				return n.replace(/[^-0-9a-zA-Z_]/g, '');
146			}).join(' ');
147			val = $.trim(val.replace(/\s+/g, ' '));
148			$(this).val(val);
149		});
150
151		pane.find(':input.color').each(function(i) {
152			var val = $(this).val();
153			val = val.replace(/[^0-9a-fA-F]/g, '');
154			$(this).val(val);
155		});
156
157		pane.find(':input.filesize').each(function(i) {
158			var val = $(this).val();
159			val = val.replace(/[^0-9kKmMbB]/g, '');
160			$(this).val(val);
161		});
162
163		pane.find(':input.filetype').each(function(i) {
164			var val = $(this).val();
165			val = val.replace(/[^0-9a-zA-Z.,|\s]/g, '');
166			$(this).val(val);
167		});
168
169		pane.find(':input.date').each(function(i) {
170			var val = $(this).val();
171			if (! val.match(/^\d{4}-\d{2}-\d{2}$/)) // 'yyyy-mm-dd' ISO 8601 format
172				$(this).val('');
173		});
174
175		pane.find(':input[name="values"]').each(function(i) {
176			var val = $(this).val();
177			val = $.trim(val);
178			$(this).val(val);
179		});
180
181		pane.find('input.tag').each(function(i) {
182			var type = $(this).attr('name');
183
184			var scope = pane.find('.scope.' + type);
185			if (! scope.length)
186				scope = pane;
187
188			if (pane.find(':input[name="required"]').is(':checked'))
189				type += '*';
190
191			var name = pane.find(':input[name="name"]').val();
192
193			var options = [];
194
195			var size = scope.find(':input[name="size"]').val() || '';
196			var maxlength = scope.find(':input[name="maxlength"]').val() || '';
197			var cols = scope.find(':input[name="cols"]').val() || '';
198			var rows = scope.find(':input[name="rows"]').val() || '';
199
200			if ((cols || rows) && maxlength)
201				options.push(cols + 'x' + rows + '/' + maxlength);
202			else if (cols || rows)
203				options.push(cols + 'x' + rows);
204			else if (size || maxlength)
205				options.push(size + '/' + maxlength);
206
207			scope.find('input.option').not(':checkbox,:radio').each(function(i) {
208				var excluded = ['size', 'maxlength', 'cols', 'rows'];
209
210				if (-1 < $.inArray($(this).attr('name'), excluded))
211					return;
212
213				var val = $(this).val();
214
215				if (! val)
216					return;
217
218				if ($(this).hasClass('filetype'))
219					val = val.split(/[,|\s]+/).join('|');
220
221				if ($(this).hasClass('color'))
222					val = '#' + val;
223
224				if ('class' == $(this).attr('name')) {
225					$.each(val.split(' '), function(i, n) { options.push('class:' + n) });
226				} else {
227					options.push($(this).attr('name') + ':' + val);
228				}
229			});
230
231			scope.find('input:checkbox.option').each(function(i) {
232				if ($(this).is(':checked'))
233					options.push($(this).attr('name'));
234			});
235
236			options = (options.length > 0) ? ' ' + options.join(' ') : '';
237
238			var value = '';
239
240			if (scope.find(':input[name="values"]').val()) {
241				$.each(scope.find(':input[name="values"]').val().split("\n"), function(i, n) {
242					value += ' "' + n.replace(/["]/g, '&quot;') + '"';
243				});
244			}
245
246			if ($.tgPanes[tagType].nameless)
247				var tag = '[' + type + options + value + ']';
248			else
249				var tag = name ? '[' + type + ' ' + name + options + value + ']' : '';
250
251			$(this).val(tag);
252		});
253
254		pane.find('input.mail-tag').each(function(i) {
255			var name = pane.find(':input[name="name"]').val();
256
257			var tag = name ? '[' + name + ']' : '';
258
259			$(this).val(tag);
260		});
261
262	}
263
264	$.tgPanes = {};
265
266})(jQuery);
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Puppeteer on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)