Best JavaScript code snippet using webdriverio-monorepo
ListTests.js
Source:ListTests.js  
...232				[],233				intern.config.WAIT_TIMEOUT,234				intern.config.POLL_INTERVAL))235				.pressKeys(keys.TAB) // Press TAB236				.getActiveElement()237				.getVisibleText()238				.then(function (value) {239					assert.strictEqual(value, "Programmatic item of order 0\nlist-prog-1");240				})241				.end()242				.pressKeys(keys.ARROW_DOWN) // Press DOWN ARROW243				.getActiveElement()244				.getVisibleText()245				.then(function (value) {246					assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");247				})248				.end()249				.pressKeys(keys.ARROW_DOWN) // Press DOWN ARROW250				.getActiveElement()251				.getVisibleText()252				.then(function (value) {253					assert.strictEqual(value, "Programmatic item of order 2\nlist-prog-1");254				})255				.end()256				.pressKeys(keys.ARROW_RIGHT) // Press RIGHT ARROW257				.getActiveElement()258				.getVisibleText()259				.then(function (value) {260					assert.strictEqual(value, "Programmatic item of order 2\nlist-prog-1");261				})262				.end()263				.pressKeys(keys.ENTER) // Press ENTER264				.getActiveElement()265				.getVisibleText()266				.then(function (value) {267					assert.strictEqual(value, "Programmatic item of order 2\nlist-prog-1");268				})269				.end()270				.pressKeys(keys.ARROW_UP) // Press UP ARROW271				.getActiveElement()272				.getVisibleText()273				.then(function (value) {274					assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");275				})276				.end()277				.pressKeys(keys.TAB) // Press TAB278				.pressKeys(keys.SHIFT + keys.TAB) // Press Shift + TAB279				.pressKeys(keys.SHIFT) // release shift280				.getActiveElement()281				.getVisibleText()282				.then(function (value) {283					assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");284				})285				.end()286				.pressKeys(keys.F2) // Press F2287				.getActiveElement()288				.getVisibleText()289				.then(function (value) {290					assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");291				})292				.end()293				.pressKeys(keys.PAGE_DOWN) // Press PAGE DOWN294				.getActiveElement()295				.getVisibleText()296				.then(function (value) {297					assert.strictEqual(value, "Programmatic item of order 99\nlist-prog-1");298				})299				.end()300				.pressKeys(keys.HOME) // Press HOME301				.getActiveElement()302				.getVisibleText()303				.then(function (value) {304					assert.strictEqual(value, "Programmatic item of order 0\nlist-prog-1");305				})306				.end()307				.pressKeys(keys.END) // Press END308				.getActiveElement()309				.getVisibleText()310				.then(function (value) {311					assert.strictEqual(value, "Programmatic item of order 99\nlist-prog-1");312				})313				.end();314		},315		"keyboard navigation with custom renderers": function () {316			var remote = this.remote;317			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {318				return this.skip("no keyboard support");319			}320			if (remote.environmentType.browserName.toLowerCase() === "internet explorer") {321				// Since evt.shiftKey not set (webdriver bug), Shift-TAB is getting treated like a normal TAB,322				// and we go to an unexpected element, leading to a test failure.  Shift-TAB works when manually323				// tested though, and Shift-TAB works in some other Intern tests too.  Strange.324				return this.skip("shift-tab getting treated as normal tab, spurious test failure");325			}326			return remote327				.get("deliteful/tests/functional/list/list-cust-2.html")328				.then(pollUntil("return ('ready' in window &&  ready "329					+ "&& document.getElementById('list-cust-2') "330					+ "&& !document.querySelector('#list-cust-2 .d-list-container')"331					+	".getAttribute('aria-busy') === false) ? true : null;",332				[],333				intern.config.WAIT_TIMEOUT,334				intern.config.POLL_INTERVAL))335				.pressKeys(keys.TAB) // Press TAB336				.getActiveElement()337				.getVisibleText()338				.then(function (value) {339					assert.strictEqual(value, "Amazon\nhttp://www.amazon.com", "keystroke 1");340				})341				.end()342				.pressKeys(keys.ARROW_DOWN) // Press DOWN ARROW343				.getActiveElement()344				.getVisibleText()345				.then(function (value) {346					assert.strictEqual(value, "Dojo: The Definitive Guide\nISBN: 0596516487", "keystroke 2");347				})348				.end()349				.pressKeys(keys.ARROW_UP) // Press UP ARROW350				.getActiveElement()351				.getVisibleText()352				.then(function (value) {353					assert.strictEqual(value, "Amazon\nhttp://www.amazon.com", "keystroke 3");354				})355				.end()356				.pressKeys(keys.ARROW_DOWN) // Press DOWN ARROW357				.getActiveElement()358				.getVisibleText()359				.then(function (value) {360					assert.strictEqual(value, "Dojo: The Definitive Guide\nISBN: 0596516487", "keystroke 4");361				})362				.end()363				.pressKeys(keys.ARROW_RIGHT) // Press RIGHT ARROW364				.getActiveElement()365				.getVisibleText()366				.then(function (value) {367					assert.strictEqual(value, "Dojo: The Definitive Guide\nISBN: 0596516487", "keystroke 5");368				})369				.end()370				.pressKeys(keys.ENTER) // Enter "Actionable Mode" where you tab through elements inside of list item.371				.getActiveElement()372				.getVisibleText()373				.then(function (value) {374					assert.strictEqual(value, "Dojo: The Definitive Guide", "keystroke 6");375				})376				.end()377				.pressKeys(keys.SHIFT + keys.TAB) // Press Shift + TAB378				.pressKeys(keys.SHIFT) // release shift379				.getActiveElement()380				.getVisibleText()381				.then(function (value) {382					assert.strictEqual(value, "ISBN: 0596516487", "keystroke 7");383				})384				.end()385				.pressKeys(keys.TAB) // Press TAB386				.getActiveElement()387				.getVisibleText()388				.then(function (value) {389					assert.strictEqual(value, "Dojo: The Definitive Guide", "keystroke 8");390				})391				.end()392				.pressKeys(keys.TAB) // Press TAB393				.getActiveElement()394				.getVisibleText()395				.then(function (value) {396					assert.strictEqual(value, "ISBN: 0596516487", "keystroke 9");397				})398				.end()399				.pressKeys(keys.TAB) // Press TAB400				.getActiveElement()401				.getVisibleText()402				.then(function (value) {403					assert.strictEqual(value, "Dojo: The Definitive Guide", "keystroke 10");404				})405				.end()406				.pressKeys(keys.ARROW_UP) // Up arrow should have no effect in Actionable Mode.407				.getActiveElement()408				.getVisibleText()409				.then(function (value) {410					assert.strictEqual(value, "Dojo: The Definitive Guide", "keystroke 11");411				})412				.end()413				.pressKeys(keys.ARROW_DOWN) // Down arrow should have no effect in Actionable Mode.414				.getActiveElement()415				.getVisibleText()416				.then(function (value) {417					assert.strictEqual(value, "Dojo: The Definitive Guide", "keystroke 12");418				})419				.end()420				.execute("document.getElementById('keydownEvent').innerHTML = '';")421				.pressKeys(keys.ESCAPE) // Leave Actionable Mode.422				.getActiveElement()423				.getVisibleText()424				.then(function (value) {425					assert.strictEqual(value, "Dojo: The Definitive Guide\nISBN: 0596516487", "keystroke 13");426				})427				.end()428				.execute("return document.getElementById('keydownEvent').textContent;").then(function (text) {429					assert.strictEqual(text, "", "no keydown event on <body>");430				})431				.pressKeys(keys.SHIFT + keys.TAB)432				.pressKeys(keys.SHIFT) // release shift433				.pressKeys(keys.TAB) // Press TAB434				.getActiveElement()435				.getVisibleText()436				.then(function (value) {437					assert.strictEqual(value, "Dojo: The Definitive Guide\nISBN: 0596516487", "keystroke 14");438				})439				.end()440				.pressKeys(keys.F2) // Press F2441				.getActiveElement()442				.getVisibleText()443				.then(function (value) {444					assert.strictEqual(value, "Dojo: The Definitive Guide", "keystroke 15");445				})446				.end();447		},448		"keyboard multiple selection": function () {449			var remote = this.remote;450			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {451				return this.skip("no keyboard support");452			}453			return remote454				.get("deliteful/tests/functional/list/list-mark-1.html")455				.then(pollUntil("return ('ready' in window &&  ready "456					+ "&& document.getElementById('list-mark-1') "457					+ "&& !document.querySelector('#list-mark-1 .d-list-container')"458					+	".getAttribute('aria-busy') === false) ? true : null;",459				[],460				intern.config.WAIT_TIMEOUT,461				intern.config.POLL_INTERVAL))462				.pressKeys(keys.TAB) // Press TAB463				.getActiveElement()464				.getVisibleText()465				.then(function (value) {466					assert.strictEqual(value, "list item 0\nright text A");467				})468				.end()469				.pressKeys(keys.SPACE) // Press SPACE470				.getActiveElement()471				.getVisibleText()472				.then(function (value) {473					assert.strictEqual(value, "list item 0\nright text A");474				})475				.end()476				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell477				.getAttribute("aria-selected")478				.then(function (value) {479					assert.strictEqual(value, "true", "aria-selected list item 0, after space");480				})481				.end()482				.pressKeys(keys.SPACE) // Press SPACE483				.getActiveElement()484				.getVisibleText()485				.then(function (value) {486					assert.strictEqual(value, "list item 0\nright text A");487				})488				.end()489				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell490				.getAttribute("aria-selected")491				.then(function (value) {492					assert.strictEqual(value, "false", "aria-selected list item 0, after second space");493				})494				.end()495				.pressKeys(keys.SPACE) // Press SPACE496				.getActiveElement()497				.getVisibleText()498				.then(function (value) {499					assert.strictEqual(value, "list item 0\nright text A");500				})501				.end()502				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell503				.getAttribute("aria-selected")504				.then(function (value) {505					assert.strictEqual(value, "true", "aria-selected list item 0, after third space");506				})507				.end()508				.pressKeys(keys.ARROW_DOWN) // Press DOWN ARROW509				.getActiveElement()510				.getVisibleText()511				.then(function (value) {512					assert.strictEqual(value, "list item 1\nright text B");513				})514				.end()515				.pressKeys(keys.SPACE) // Press SPACE516				.getActiveElement()517				.getVisibleText()518				.then(function (value) {519					assert.strictEqual(value, "list item 1\nright text B");520				})521				.end()522				.findByCssSelector("[role=row]:nth-child(2)")	// aria-selected is on row, not cell523				.getAttribute("aria-selected")524				.then(function (value) {525					assert.strictEqual(value, "true", "aria-selected list item 1, after space");526				})527				.end()528				.pressKeys(keys.ARROW_UP) // Press UP ARROW529				.getActiveElement()530				.getVisibleText()531				.then(function (value) {532					assert.strictEqual(value, "list item 0\nright text A");533				})534				.end()535				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell536				.getAttribute("aria-selected", "aria-selected list item 0, at end")537				.then(function (value) {538					assert.strictEqual(value, "true");539				})540				.end();541		},542		"keyboard single selection": function () {543			var remote = this.remote;544			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {545				return this.skip("no keyboard support");546			}547			return remote548				.get("deliteful/tests/functional/list/list-mark-2.html")549				.then(pollUntil("return ('ready' in window &&  ready "550					+ "&& document.getElementById('list-mark-2') "551					+ "&& !document.querySelector('#list-mark-2 .d-list-container')"552					+	".getAttribute('aria-busy') === false) ? true : null;",553				[],554				intern.config.WAIT_TIMEOUT,555				intern.config.POLL_INTERVAL))556				.pressKeys(keys.TAB) // Press TAB557				.getActiveElement()558				.getVisibleText()559				.then(function (value) {560					assert.strictEqual(value, "list item 0\nright text 1");561				})562				.end()563				.pressKeys(keys.SPACE) // Press SPACE564				.getActiveElement()565				.getVisibleText()566				.then(function (value) {567					assert.strictEqual(value, "list item 0\nright text 1");568				})569				.end()570				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell571				.getAttribute("aria-selected")572				.then(function (value) {573					assert.strictEqual(value, "true", "aria-selected list item 0, after space");574				})575				.end()576				.sleep(10)577				.pressKeys(keys.SPACE) // Press SPACE578				.getActiveElement()579				.getVisibleText()580				.then(function (value) {581					assert.strictEqual(value, "list item 0\nright text 1");582				})583				.end()584				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell585				.getAttribute("aria-selected")586				.then(function (value) {587					assert.strictEqual(value, "false", "aria-selected list item 0, after second space");588				})589				.end()590				.pressKeys(keys.SPACE) // Press SPACE591				.getActiveElement()592				.getVisibleText()593				.then(function (value) {594					assert.strictEqual(value, "list item 0\nright text 1");595				})596				.end()597				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell598				.getAttribute("aria-selected")599				.then(function (value) {600					assert.strictEqual(value, "true", "aria-selected list item 0, after third space");601				})602				.end()603				.pressKeys(keys.ARROW_DOWN) // Press DOWN ARROW604				.getActiveElement()605				.getVisibleText()606				.then(function (value) {607					assert.strictEqual(value, "list item 1\nright text 2");608				})609				.end()610				.pressKeys(keys.SPACE) // Press SPACE611				.getActiveElement()612				.getVisibleText()613				.then(function (value) {614					assert.strictEqual(value, "list item 1\nright text 2");615				})616				.end()617				.findByCssSelector("[role=row]:nth-child(2)")	// aria-selected is on row, not cell618				.getAttribute("aria-selected")619				.then(function (value) {620					assert.strictEqual(value, "true", "aria-selected list item 1, after space");621				})622				.end()623				.pressKeys(keys.ARROW_UP) // Press UP ARROW624				.getActiveElement()625				.getVisibleText()626				.then(function (value) {627					assert.strictEqual(value, "list item 0\nright text 1");628				})629				.end()630				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell631				.getAttribute("aria-selected")632				.then(function (value) {633					assert.strictEqual(value, "false", "aria-selected list item 0, at end");634				})635				.end();636		},637		"keyboard radio selection": function () {638			var remote = this.remote;639			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {640				return this.skip("no keyboard support");641			}642			return remote643				.get("deliteful/tests/functional/list/list-mark-5.html")644				.then(pollUntil("return ('ready' in window &&  ready "645					+ "&& document.getElementById('list-mark-5') "646					+ "&& !document.querySelector('#list-mark-5 .d-list-container')"647					+	".getAttribute('aria-busy') === false) ? true : null;",648				[],649				intern.config.WAIT_TIMEOUT,650				intern.config.POLL_INTERVAL))651				.pressKeys(keys.TAB) // Press TAB652				.getActiveElement()653				.getVisibleText()654				.then(function (value) {655					assert.strictEqual(value, "list item 0\nright text 1", "keystroke 1");656				})657				.end()658				.pressKeys(keys.SPACE) // Press SPACE659				.getActiveElement()660				.getVisibleText()661				.then(function (value) {662					assert.strictEqual(value, "list item 0\nright text 1", "keystroke 2");663				})664				.end()665				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell666				.getAttribute("aria-selected")667				.then(function (value) {668					assert.strictEqual(value, "true", "keystroke 2");669				})670				.end()671				.sleep(10)672				.pressKeys(keys.SPACE) // Press SPACE673				.getActiveElement()674				.getVisibleText()675				.then(function (value) {676					assert.strictEqual(value, "list item 0\nright text 1", "keystroke 3");677				})678				.end()679				.findByCssSelector("[role=row]")	// aria-selected is on row, not cell680				.getAttribute("aria-selected")681				.then(function (value) {682					assert.strictEqual(value, "true", "keystroke 3");683				})684				.end();685		},686		"keyboard search": function () {687			var remote = this.remote;688			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {689				return this.skip("no keyboard support");690			}691			return remote692				.get("deliteful/tests/functional/list/list-mark-1.html")693				.then(pollUntil("return ('ready' in window &&  ready "694					+ "&& document.getElementById('list-mark-1') "695					+ "&& !document.querySelector('#list-mark-1 .d-list-container')"696					+	".getAttribute('aria-busy') === false) ? true : null;",697				[],698				intern.config.WAIT_TIMEOUT,699				intern.config.POLL_INTERVAL))700				.pressKeys(keys.TAB) // Press TAB701				.getActiveElement()702				.getVisibleText()703				.then(function (value) {704					assert.strictEqual(value, "list item 0\nright text A", "initial");705				})706				.end()707				.pressKeys("R")708				.getActiveElement()709				.getVisibleText()710				.then(function (value) {711					assert.strictEqual(value, "list item 0\nright text A", "after R");712				})713				.end()714				.sleep(10)715				.pressKeys("r")716				.getActiveElement()717				.getVisibleText()718				.then(function (value) {719					assert.strictEqual(value, "list item 0\nright text A", "after r");720				})721				.end()722				.sleep(10)723				.pressKeys("L")724				.getActiveElement()725				.getVisibleText()726				.then(function (value) {727					assert.strictEqual(value, "list item 1\nright text B", "after L");728				})729				.end()730				.sleep(10)731				.pressKeys("l")732				.getActiveElement()733				.getVisibleText()734				.then(function (value) {735					assert.strictEqual(value, "list item 2\nright text C", "after l");736				})737				.end();738		},739		"custom keyboard navigation": function () {740			var remote = this.remote;741			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {742				return this.skip("no keyboard support");743			}744			return remote745				.get("deliteful/tests/functional/list/list-cust-1.html")746				.then(pollUntil("return ('ready' in window &&  ready "747					+ "&& document.getElementById('list-cust-1') "748					+ "&& !document.querySelector('#list-cust-1 .d-list-container')"749					+	".getAttribute('aria-busy') === false) ? true : null;",750				[],751				intern.config.WAIT_TIMEOUT,752				intern.config.POLL_INTERVAL))753				.pressKeys(keys.TAB) // Press TAB754				.pressKeys(keys.ENTER) // Press ENTER755				.getActiveElement().getVisibleText().then(function (value) {756					assert.strictEqual(value, "1 tabindex 1");757				}).end()758				.pressKeys(keys.TAB) // Press TAB759				.getActiveElement().getVisibleText().then(function (value) {760					assert.strictEqual(value, "4 tabindex 2");761				}).end()762				.pressKeys(keys.TAB) // Press TAB763				.getActiveElement().getVisibleText().then(function (value) {764					assert.strictEqual(value, "2 tabindex 3");765				}).end()766				.pressKeys(keys.TAB) // Press TAB767				.getActiveElement().getVisibleText().then(function (value) {768					assert.strictEqual(value, "5 tabindex 3");769				}).end()770				.pressKeys(keys.TAB) // Press TAB771				.getActiveElement().getVisibleText().then(function (value) {772					assert.strictEqual(value, "6 tabindex 0");773				}).end();774		},775		// Test of the recommended table layout, where each cell is either text or a single control.776		// Arrow key navigation goes directly to the controls.777		"table (multiple gridcells per row) with control cells": function () {778			var remote = this.remote;779			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {780				return this.skip("no keyboard support");781			}782			return remote783				.get("deliteful/tests/functional/list/table-1.html")784				.then(pollUntil("return ('ready' in window &&  ready "785					+ "&& document.getElementById('table-1') "786					+ "&& !document.querySelector('#table-1 .d-list-container')"787					+	".getAttribute('aria-busy') === false) ? true : null;",788					[],789					intern.config.WAIT_TIMEOUT,790					intern.config.POLL_INTERVAL))791				.pressKeys(keys.TAB)792				.getActiveElement().getVisibleText().then(function (value) {793					assert.strictEqual(value, "Amazon", "after tabbing into table");794				}).end()795				.pressKeys(keys.TAB)796				.getActiveElement().getAttribute("id").then(function (value) {797					assert.strictEqual(value, "after", "focus after shift-tab");798				}).end()799				.pressKeys(keys.SHIFT + keys.TAB)800				.pressKeys(keys.SHIFT)		// release shift key801				.getActiveElement().getVisibleText().then(function (value) {802					assert.strictEqual(value, "Amazon", "after shift-tabbing back into table");803				}).end()804				.pressKeys(keys.ARROW_DOWN)805				.getActiveElement().getVisibleText().then(function (value) {806					assert.strictEqual(value, "Dojo: The Definitive Guide", "after arrow down");807				}).end()808				.pressKeys(keys.ARROW_RIGHT)809				.getActiveElement().getVisibleText().then(function (value) {810					assert.strictEqual(value, "ISBN: 0596516487", "after arrow right");811				}).end()812				.pressKeys(keys.ARROW_UP)813				.getActiveElement()814					.getVisibleText().then(function (value) {815						assert.strictEqual(value, "http://www.amazon.com", "after arrow up, link text");816					})817					.getAttribute("href").then(function (value) {818						assert.strictEqual(value, "http://www.amazon.com", "focused on link, not cell");819					})820				.end()821				.pressKeys(keys.ARROW_LEFT)822				.getActiveElement().getVisibleText().then(function (value) {823					assert.strictEqual(value, "Amazon", "after left arrow");824				}).end();825		},826		// Test of old-style where you need to use ENTER and ESC (or F2) to navigate the widgets within a cell.827		"table (multiple gridcells per row) with column with multiple widgets": function () {828			var remote = this.remote;829			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {830				return this.skip("no keyboard support");831			}832			return remote833				.get("deliteful/tests/functional/list/table-2.html")834				.then(pollUntil("return ('ready' in window &&  ready "835					+ "&& document.getElementById('table-2') "836					+ "&& !document.querySelector('#table-2 .d-list-container')"837					+	".getAttribute('aria-busy') === false) ? true : null;",838					[],839					intern.config.WAIT_TIMEOUT,840					intern.config.POLL_INTERVAL))841				.pressKeys(keys.TAB)842				.getActiveElement().getVisibleText().then(function (value) {843					assert.strictEqual(value, "Apple", "after tabbing into table");844				}).end()845				.pressKeys(keys.TAB)846				.getActiveElement().getAttribute("id").then(function (value) {847					assert.strictEqual(value, "after", "focus after tab");848				}).end()849				.pressKeys(keys.SHIFT + keys.TAB)850				.pressKeys(keys.SHIFT)		// release shift key851				.getActiveElement().getVisibleText().then(function (value) {852					assert.strictEqual(value, "Apple", "after shift-tabbing back into table");853				}).end()854				.pressKeys(keys.ARROW_RIGHT)855				.getActiveElement().getAttribute("class").then(function (value) {856					assert.match(value, /complex-cell/, "after arrow right, focused on second cell");857				}).end()858				.pressKeys(keys.ENTER)859				.getActiveElement().getAttribute("id").then(function (value) {860					assert.strictEqual(value, "apple-input1", "after Enter, focused on first input");861				}).end()862				.pressKeys("abd")863				.pressKeys(keys.ARROW_LEFT)		// should navigate within <input>864				.pressKeys("c")865				.getActiveElement().getAttribute("id").then(function (value) {866					assert.strictEqual(value, "apple-input1", "still focused on first input");867				}).end()868				.execute("return document.activeElement.value;").then(function (value) {869					assert.strictEqual(value, "abcd", "first input value, confirms left arrow navigated within it");870				}).end()871				.pressKeys(keys.TAB)872				.getActiveElement().getAttribute("id").then(function (value) {873					assert.strictEqual(value, "apple-input2", "tabbed to second input");874				}).end()875				.pressKeys(keys.TAB)876				.getActiveElement().getAttribute("id").then(function (value) {877					assert.strictEqual(value, "apple-button", "tabbed to button");878				}).end()879				.pressKeys(keys.TAB)880				.getActiveElement().getAttribute("id").then(function (value) {881					assert.strictEqual(value, "apple-input1", "tabbed back to first input");882				}).end()883				.pressKeys(keys.ESCAPE)884				.getActiveElement().getAttribute("class").then(function (value) {885					assert.match(value, /complex-cell/, "after esc, focused on second cell");886				}).end()887				.pressKeys(keys.ARROW_LEFT)888				.getActiveElement().getVisibleText().then(function (value) {889					assert.strictEqual(value, "Apple", "arrow left back to first cell");890				}).end();891		}892	});...AriaListboxTests.js
Source:AriaListboxTests.js  
...135				intern.config.POLL_INTERVAL))136				.then(function () {137					return remote138						.pressKeys(keys.TAB)139						.getActiveElement()140						.getVisibleText()141						.then(function (value) {142							assert.strictEqual(value, "Programmatic item of order 0\nlist-prog-1");143						})144						.end()145						.pressKeys(keys.ARROW_DOWN)146						.getActiveElement()147						.getVisibleText()148						.then(function (value) {149							assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");150						})151						.end()152						.pressKeys(keys.ARROW_DOWN)153						.getActiveElement()154						.getVisibleText()155						.then(function (value) {156							assert.strictEqual(value, "Programmatic item of order 2\nlist-prog-1");157						})158						.end()159						.pressKeys(keys.ARROW_RIGHT)160						.getActiveElement()161						.getVisibleText()162						.then(function (value) {163							assert.strictEqual(value, "Programmatic item of order 2\nlist-prog-1");164						})165						.end()166						.pressKeys(keys.ENTER)167						.getActiveElement()168						.getVisibleText()169						.then(function (value) {170							assert.strictEqual(value, "Programmatic item of order 2\nlist-prog-1");171						})172						.end()173						.pressKeys(keys.ARROW_UP)174						.getActiveElement()175						.getVisibleText()176						.then(function (value) {177							assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");178						})179						.end()180						.pressKeys(keys.TAB)181						.pressKeys(keys.SHIFT + keys.TAB)182						.pressKeys(keys.SHIFT) // release shift183						.getActiveElement()184						.getVisibleText()185						.then(function (value) {186							assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");187						})188						.end()189						.pressKeys(keys.F2)190						.getActiveElement()191						.getVisibleText()192						.then(function (value) {193							assert.strictEqual(value, "Programmatic item of order 1\nlist-prog-1");194						})195						.end();196				});197		},198		"keyboard navigation with categorized items": function () {199			var remote = this.remote;200			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {201				return this.skip("no keyboard support");202			}203			return remote204				.get("deliteful/tests/functional/list/listbox-mark-3.html")205				.then(pollUntil("return ('ready' in window &&  ready "206					+ "&& document.getElementById('list-mark-3') "207					+ "&& !document.querySelector('#list-mark-3 .d-list-container')"208					+	".getAttribute('aria-busy') === false) ? true : null;",209				[],210				intern.config.WAIT_TIMEOUT,211				intern.config.POLL_INTERVAL))212				.then(function () {213					return remote214						.pressKeys(keys.TAB)215						.getActiveElement()216						.getVisibleText()217						.then(function (value) {218							assert.strictEqual(value, "list item 0\nA");219						})220						.end()221						.pressKeys(keys.ARROW_DOWN) 	//5 times222						.pressKeys(keys.ARROW_DOWN)223						.pressKeys(keys.ARROW_DOWN)224						.pressKeys(keys.ARROW_DOWN)225						.pressKeys(keys.ARROW_DOWN)226						.getActiveElement()227						.getVisibleText()228						.then(function (value) {229							assert.strictEqual(value, "list item 5\nB");230						})231						.end();232				});233		},234		// TODO: ADD A TEST: CLICKING ON A CATEGORY HEADER (see https://github.com/ibm-js/delite/issues/229)235		"keyboard multiple selection": function () {236			var remote = this.remote;237			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {238				return this.skip("no keyboard support");239			}240			return remote241				.get("deliteful/tests/functional/list/listbox-mark-1.html")242				.then(pollUntil("return ('ready' in window &&  ready "243					+ "&& document.getElementById('list-mark-1') "244					+ "&& !document.querySelector('#list-mark-1 .d-list-container')"245					+	".getAttribute('aria-busy') === false) ? true : null;",246				[],247				intern.config.WAIT_TIMEOUT,248				intern.config.POLL_INTERVAL))249				.then(function () {250					return remote251						.pressKeys(keys.TAB)252						.getActiveElement()253						.getVisibleText()254						.then(function (value) {255							assert.strictEqual(value, "list item 0\nright text A");256						})257						.end()258						.pressKeys(keys.SPACE)259						.getActiveElement()260						.getVisibleText()261						.then(function (value) {262							assert.strictEqual(value, "list item 0\nright text A");263						})264						.getAttribute("aria-selected")265						.then(function (value) {266							assert.strictEqual(value, "true");267						})268						.end()269						.pressKeys(keys.SPACE)270						.getActiveElement()271						.getVisibleText()272						.then(function (value) {273							assert.strictEqual(value, "list item 0\nright text A");274						})275						.getAttribute("aria-selected")276						.then(function (value) {277							assert.strictEqual(value, "false");278						})279						.end();280				});281		},282		"keyboard single selection": function () {283			var remote = this.remote;284			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {285				return this.skip("no keyboard support");286			}287			return remote288				.get("deliteful/tests/functional/list/listbox-mark-2.html")289				.then(pollUntil("return ('ready' in window &&  ready "290					+ "&& document.getElementById('list-mark-2') "291					+ "&& !document.querySelector('#list-mark-2 .d-list-container')"292					+	".getAttribute('aria-busy') === false) ? true : null;",293				[],294				intern.config.WAIT_TIMEOUT,295				intern.config.POLL_INTERVAL))296				.then(function () {297					return remote298						.pressKeys(keys.TAB)299						.getActiveElement()300						.getVisibleText()301						.then(function (value) {302							assert.strictEqual(value, "list item 0\nright text 1", "keystroke 1");303						})304						.end()305						.pressKeys(keys.SPACE)306						.getActiveElement()307						.getVisibleText()308						.then(function (value) {309							assert.strictEqual(value, "list item 0\nright text 1", "keystroke 2");310						})311						.getAttribute("aria-selected")312						.then(function (value) {313							assert.strictEqual(value, "true", "keystroke 2");314						})315						.end()316						.sleep(10)317						.pressKeys(keys.SPACE)318						.getActiveElement()319						.getVisibleText()320						.then(function (value) {321							assert.strictEqual(value, "list item 0\nright text 1", "keystroke 3");322						})323						.getAttribute("aria-selected")324						.then(function (value) {325							assert.strictEqual(value, "false", "keystroke 3");326						})327						.end()328						.pressKeys(keys.END)329						.getActiveElement()330						.getVisibleText()331						.then(function (value) {332							assert.strictEqual(value, "list item 9\nright text 10", "keystroke 4");333						})334						.getAttribute("aria-selected")335						.then(function (value) {336							assert.strictEqual(value, "false", "keystroke 4");337						})338						.end()339						.pressKeys(keys.PAGE_DOWN)340						.getActiveElement()341						.getVisibleText()342						.then(function (value) {343							assert.strictEqual(value, "list item 9\nright text 10", "keystroke 5");344						})345						.getAttribute("aria-selected")346						.then(function (value) {347							assert.strictEqual(value, "false", "keystroke 5");348						})349						.end()350						.pressKeys(keys.HOME)351						.getActiveElement()352						.getVisibleText()353						.then(function (value) {354							assert.strictEqual(value, "list item 0\nright text 1", "keystroke 6");355						})356						.getAttribute("aria-selected")357						.then(function (value) {358							assert.strictEqual(value, "false", "keystroke 6");359						})360						.end()361						.pressKeys(keys.PAGE_UP)362						.getActiveElement()363						.getVisibleText()364						.then(function (value) {365							assert.strictEqual(value, "list item 0\nright text 1", "keystroke 7");366						})367						.getAttribute("aria-selected")368						.then(function (value) {369							assert.strictEqual(value, "false", "keystroke 7");370						})371						.end();372				});373		},374		"keyboard search": function () {375			var remote = this.remote;376			if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {377				return this.skip("no keyboard support");378			}379			return remote380				.get("deliteful/tests/functional/list/listbox-mark-1.html")381				.then(pollUntil("return ('ready' in window &&  ready "382					+ "&& document.getElementById('list-mark-1') "383					+ "&& !document.querySelector('#list-mark-1 .d-list-container')"384					+	".getAttribute('aria-busy') === false) ? true : null;",385				[],386				intern.config.WAIT_TIMEOUT,387				intern.config.POLL_INTERVAL))388				.then(function () {389					return remote390						.pressKeys(keys.TAB)391						.getActiveElement()392						.getVisibleText()393						.then(function (value) {394							assert.strictEqual(value, "list item 0\nright text A");395						})396						.end()397						.pressKeys("R")398						.getActiveElement()399						.getVisibleText()400						.then(function (value) {401							assert.strictEqual(value, "list item 0\nright text A");402						})403						.end()404						.sleep(10)405						.pressKeys("r")406						.getActiveElement()407						.getVisibleText()408						.then(function (value) {409							assert.strictEqual(value, "list item 0\nright text A");410						})411						.end()412						.sleep(10)413						.pressKeys("L")414						.getActiveElement()415						.getVisibleText()416						.then(function (value) {417							assert.strictEqual(value, "list item 1\nright text B");418						})419						.end()420						.sleep(10)421						.pressKeys("l")422						.getActiveElement()423						.getVisibleText()424						.then(function (value) {425							assert.strictEqual(value, "list item 2\nright text C");426						})427						.end();428				});429		}430	});...scrollspy.js
Source:scrollspy.js  
...61      ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);62      ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.$el), 1);63      ScrollSpy._count--;64      this._removeEventHandlers();65      $(this.options.getActiveElement(this.$el.attr('id'))).removeClass(this.options.activeClass);66      this.el.M_ScrollSpy = undefined;67    }68    /**69     * Setup Event Handlers70     */71    _setupEventHandlers() {72      let throttledResize = M.throttle(this._handleWindowScroll, 200);73      this._handleThrottledResizeBound = throttledResize.bind(this);74      this._handleWindowScrollBound = this._handleWindowScroll.bind(this);75      if (ScrollSpy._count === 1) {76        window.addEventListener('scroll', this._handleWindowScrollBound);77        window.addEventListener('resize', this._handleThrottledResizeBound);78        document.body.addEventListener('click', this._handleTriggerClick);79      }80    }81    /**82     * Remove Event Handlers83     */84    _removeEventHandlers() {85      if (ScrollSpy._count === 0) {86        window.removeEventListener('scroll', this._handleWindowScrollBound);87        window.removeEventListener('resize', this._handleThrottledResizeBound);88        document.body.removeEventListener('click', this._handleTriggerClick);89      }90    }91    /**92     * Handle Trigger Click93     * @param {Event} e94     */95    _handleTriggerClick(e) {96      let $trigger = $(e.target);97      for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {98        let scrollspy = ScrollSpy._elements[i];99        if ($trigger.is('a[href="#' + scrollspy.$el.attr('id') + '"]')) {100          e.preventDefault();101          let offset = scrollspy.$el.offset().top + 1;102          anim({103            targets: [document.documentElement, document.body],104            scrollTop: offset - scrollspy.options.scrollOffset,105            duration: 400,106            easing: 'easeOutCubic'107          });108          break;109        }110      }111    }112    /**113     * Handle Window Scroll114     */115    _handleWindowScroll() {116      // unique tick id117      ScrollSpy._ticks++;118      // viewport rectangle119      let top = M.getDocumentScrollTop(),120        left = M.getDocumentScrollLeft(),121        right = left + window.innerWidth,122        bottom = top + window.innerHeight;123      // determine which elements are in view124      let intersections = ScrollSpy._findElements(top, right, bottom, left);125      for (let i = 0; i < intersections.length; i++) {126        let scrollspy = intersections[i];127        let lastTick = scrollspy.tickId;128        if (lastTick < 0) {129          // entered into view130          scrollspy._enter();131        }132        // update tick id133        scrollspy.tickId = ScrollSpy._ticks;134      }135      for (let i = 0; i < ScrollSpy._elementsInView.length; i++) {136        let scrollspy = ScrollSpy._elementsInView[i];137        let lastTick = scrollspy.tickId;138        if (lastTick >= 0 && lastTick !== ScrollSpy._ticks) {139          // exited from view140          scrollspy._exit();141          scrollspy.tickId = -1;142        }143      }144      // remember elements in view for next tick145      ScrollSpy._elementsInView = intersections;146    }147    /**148     * Find elements that are within the boundary149     * @param {number} top150     * @param {number} right151     * @param {number} bottom152     * @param {number} left153     * @return {Array.<ScrollSpy>}   A collection of elements154     */155    static _findElements(top, right, bottom, left) {156      let hits = [];157      for (let i = 0; i < ScrollSpy._elements.length; i++) {158        let scrollspy = ScrollSpy._elements[i];159        let currTop = top + scrollspy.options.scrollOffset || 200;160        if (scrollspy.$el.height() > 0) {161          let elTop = scrollspy.$el.offset().top,162            elLeft = scrollspy.$el.offset().left,163            elRight = elLeft + scrollspy.$el.width(),164            elBottom = elTop + scrollspy.$el.height();165          let isIntersect = !(166            elLeft > right ||167            elRight < left ||168            elTop > bottom ||169            elBottom < currTop170          );171          if (isIntersect) {172            hits.push(scrollspy);173          }174        }175      }176      return hits;177    }178    _enter() {179      ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {180        return value.height() != 0;181      });182      if (ScrollSpy._visibleElements[0]) {183        $(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(184          this.options.activeClass185        );186        if (187          ScrollSpy._visibleElements[0][0].M_ScrollSpy &&188          this.id < ScrollSpy._visibleElements[0][0].M_ScrollSpy.id189        ) {190          ScrollSpy._visibleElements.unshift(this.$el);191        } else {192          ScrollSpy._visibleElements.push(this.$el);193        }194      } else {195        ScrollSpy._visibleElements.push(this.$el);196      }197      $(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(198        this.options.activeClass199      );200    }201    _exit() {202      ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {203        return value.height() != 0;204      });205      if (ScrollSpy._visibleElements[0]) {206        $(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(207          this.options.activeClass208        );209        ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((el) => {210          return el.attr('id') != this.$el.attr('id');211        });212        if (ScrollSpy._visibleElements[0]) {213          // Check if empty214          $(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(215            this.options.activeClass216          );217        }218      }219    }220  }221  /**222   * @static223   * @memberof ScrollSpy224   * @type {Array.<ScrollSpy>}225   */226  ScrollSpy._elements = [];227  /**228   * @static...DateTime.js
Source:DateTime.js  
...30        })31        const d = new Date('2003-04-05')32        userEvent.tab()33        expect(result.getByLabelText('Year')).toHaveFocus()34        expect(getActiveElement()).toHaveTextContent(new RegExp('^0*' + d.getFullYear() + '$'))35        // next year36        fireEvent.keyDown(getActiveElement(), {key: 'ArrowUp'})37        d.setFullYear(d.getFullYear() +1)38        // next aspect39        fireEvent.keyDown(getActiveElement(), {key: 'ArrowRight'})40        expect(getLiformValue()).toEqual(dateUtil.formatByString(d, 'yyyy-MM-dd'))41        expect(result.getByLabelText('Month')).toHaveFocus()42        expect(getActiveElement()).toHaveTextContent(new RegExp('^0*' + (d.getMonth()+1) + '$'))43    })44    it('Render and change date input per typing', () => {45        const { result, getActiveElement, getLiformValue } = testLifield({46            schema: {47                type: 'string',48                widget: 'date',49                title: 'foo',50            },51            value: '2001-02-03',52        })53        const d = new Date('2001-02-03')54        userEvent.tab()55        userEvent.click(result.getByLabelText('Month'))56        expect(result.getByLabelText('Month')).toHaveFocus()57        // this should jump to the next aspect58        // can not use userEvent.type due to https://github.com/testing-library/user-event/issues/44259        // userEvent.type(getActiveElement(), '8')60        fireEvent.input(getActiveElement(), {target: {textContent: '8'}})61        d.setMonth(7)62        expect(getLiformValue()).toEqual(dateUtil.formatByString(d, 'yyyy-MM-dd'))63        expect(result.getByLabelText('Day of the month')).toHaveFocus()64        expect(getActiveElement()).toHaveTextContent(new RegExp('^0*' + (d.getDate()) + '$'))65        // userEvent.type(getActiveElement(), '1')66        fireEvent.input(getActiveElement(), {target: {textContent: '1'}})67        expect(getLiformValue()).toEqual(dateUtil.formatByString(d, 'yyyy-MM-dd'))68        expect(getActiveElement()).toHaveTextContent('01')69        // userEvent.type(getActiveElement(), '7')70        fireEvent.input(getActiveElement(), {target: {textContent: '17'}})71        d.setDate(17)72        expect(getLiformValue()).toEqual(dateUtil.formatByString(d, 'yyyy-MM-dd'))73    })74    it('Render and change time input', async () => {75        const { result, getLiformValue } = testLifield({76            schema: {77                type: 'string',78                widget: 'time',79                title: 'foo',80            },81            value: '13:14',82        })83        userEvent.click(result.getByLabelText('foo'))84        userEvent.click(result.getByText('AM'))...KeyboardTab.js
Source:KeyboardTab.js  
...19				}, null, 5000));20		});21		test.test('grids with and without headers -> tab key', function () {22			return this.remote23				.getActiveElement()24					.getAttribute('id')25					.then(function (id) {26						assert.strictEqual(id, 'showHeaderButton', 'Focus is on the button: ' + id);27					})28					.type(tabKey)29					.end()30				.getActiveElement()31					.getAttribute('role').then(function (role) {32						assert.strictEqual(role, 'columnheader', 'Focus is on a column header: ' + role);33					})34					.type(tabKey)35					.end()36				.getActiveElement()37					.getAttribute('role').then(function (role) {38						assert.strictEqual(role, 'gridcell', 'Focus is on a grid cell: ' + role);39					})40					.getVisibleText()41					.then(function (text) {42						assert.strictEqual(text, '0', 'The cell with focus contains 0: ' + text);43					})44					.type(tabKey)45					.end()46				.getActiveElement()47					.getAttribute('role').then(function (role) {48						assert.strictEqual(role, 'gridcell', 'Focus is on a grid cell: ' + role);49					})50					.getVisibleText()51					.then(function (text) {52						assert.strictEqual(text, '10', 'The cell with focus contains 10: ' + text);53					})54					.end()55				.findById('showHeaderButton')56					.click()57					.end()58				.getActiveElement()59					.getAttribute('id')60					.then(function (id) {61						assert.strictEqual(id, 'showHeaderButton', 'Focus is on the button: ' + id);62					})63					.type(tabKey)64					.end()65				.getActiveElement()66					.getAttribute('role').then(function (role) {67						assert.strictEqual(role, 'columnheader', 'Focus is on a column header: ' + role);68					})69					.type(tabKey)70					.end()71				.getActiveElement()72					.getAttribute('role').then(function (role) {73						assert.strictEqual(role, 'gridcell', 'Focus is on a grid cell: ' + role);74					})75					.getVisibleText()76					.then(function (text) {77						assert.strictEqual(text, '0', 'The cell with focus contains 0: ' + text);78					})79					.type(tabKey)80					.end()81				.getActiveElement()82					.getAttribute('role').then(function (role) {83						assert.strictEqual(role, 'columnheader', 'Focus is on a column header: ' + role);84					})85					.type(tabKey)86					.end()87				.getActiveElement()88					.getAttribute('role').then(function (role) {89						assert.strictEqual(role, 'gridcell', 'Focus is on a grid cell: ' + role);90					})91					.getVisibleText()92					.then(function (text) {93						assert.strictEqual(text, '10', 'The cell with focus contains 10: ' + text);94					});95		});96	});...preferences.js
Source:preferences.js  
...14    }15    function selectTab() {16        var tabName = $(this).prop('id');17        if (tabName == active) return;18        getActiveElement().toggleClass('active');19        active = tabName;20        loadTab();21    }22    function loadTab() {23        modals.destroyModal('preferences');24        store.set('preferences.activeTab', active);25        $('#preferences-content').load(__dirname + '/modals/preferences/' + getActiveElement().data('url'));26        getActiveElement().toggleClass('active');27    }28    function getActiveElement() {29        return $(`#${active}`);30    }...getActiveElement-test.js
Source:getActiveElement-test.js  
...9jest.unmock('getActiveElement');10var getActiveElement = require('getActiveElement');11describe('getActiveElement', () => {12  it('returns body when there is no activeElement', () => {13    var element = getActiveElement();14    expect(element.tagName).toEqual('BODY');15  });16  it('uses optional document parameter when provided', () => {17    var iframe = document.createElement('iframe');18    document.body.appendChild(iframe);19    var iframeDocument = iframe.contentDocument;20    var element = getActiveElement(iframeDocument);21    try {22      expect(element.ownerDocument).toBe(iframeDocument);23      expect(element.ownerDocument).not.toBe(document);24    } finally {25      document.body.removeChild(iframe);26    }27  });...getActiveElement_spec.js
Source:getActiveElement_spec.js  
...6describeIfNoWindow('getActiveElement', () => {7  describe('without `document`', () => {8    it('returns false', () => {9      expect(typeof document).to.equal('undefined');10      expect(getActiveElement()).to.equal(false);11    });12  });13  wrap()14  .withGlobal('document', () => ({}))15  .describe('with `document`', () => {16    it('returns undefined without `document.activeElement`', () => {17      expect(getActiveElement()).to.be.an('undefined');18    });19    wrap()20    .withOverride(() => document, 'activeElement', () => test)21    .it('returns activeElement value with `document.activeElement', () => {22      expect(getActiveElement()).to.equal(test);23    });24  });...Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3    desiredCapabilities: {4    }5};6    .remote(options)7    .init()8    .setValue('#lst-ib', 'WebdriverIO')9    .keys('\uE007')10    .getTitle().then(function(title) {11        console.log('Title was: ' + title);12    })13    .end();14var webdriver = require('selenium-webdriver'),15    until = webdriver.until;16var driver = new webdriver.Builder()17    .forBrowser('firefox')18    .build();19driver.findElement(By.name('q')).sendKeys('webdriver');20driver.findElement(By.name('btnG')).click();21driver.wait(until.titleIs('webdriver - Google Search'), 1000);22driver.quit();Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4    .init()5    .setValue('#lst-ib', 'WebdriverIO')6    .keys('Enter')7    .getTitle().then(function(title) {8        console.log('Title was: ' + title);9    })10    .end();11client.getActiveElement().then(function (element) {12    console.log(element);13});14client.getActiveElement().tUsing AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3  desiredCapabilities: {4  }5};6  .remote(options)7  .init()8  .execute(function() {9    return document.activeElement;10  })11  .then(function(result) {12    console.log(result.value);13  })14  .end();15var webdriver = require('selenium-webdriver');16var driver = new webdriver.Builder().forBrowser('chrome').build();17driver.executeScript(function() {18  return document.activeElement;19}).then(function(result) {20  console.log(result);21  driver.quit();22});Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4.init()5.waitForVisible('body', 1000)6.click('#lst-ib')7.keys('webdriverio')8.pause(1000)9.click('#tsbb')10.pause(1000)11.getTitle().then(function(title) {12console.log('Title was: ' + title);13})14.end();15var webdriverio = require('webdriverio');16var options = { desiredCapabilities: { browserName: 'chrome' } };17var client = webdriverio.remote(options);18.init()19.waitForVisible('body', 1000)20.click('#lst-ib')21.keys('webdriverio')22.pause(1000)23.click('#tsbb')24.pause(1000)25.getActiveElement().then(function(activeElement) {26console.log('Active Element is: ' + activeElement);27})28.end();29var webdriverio = require('webdriverio');30var options = { desiredCapabilities: { browserName: 'chrome' } };31var client = webdriverio.remote(options);32.init()33.waitForVisible('body', 1000)34.click('#lst-ib')35.keys('webdriverio')36.pause(1000)37.click('#tsbb')38.pause(1000)39.getActiveElement().then(function(activeElement) {40activeElement.getText().then(function(text) {41console.log('Text of the active element is: ' + text);42});43})44.end();Using AI Code Generation
1const webdriverio = require('webdriverio');2const options = {3    desiredCapabilities: {4    }5}6    .remote(options)7    .init()8    .click('a[href="/docs/gettingstarted.html"]')9    .getTitle().then(function (title) {10        console.log('Title was: ' + title);11    })12    .elements('#search_input_react').then(function (elem) {13        console.log(elem.value[0].ELEMENT);14    })15    .end();16const webdriverio = require('webdriverio');17const options = {18    desiredCapabilities: {19    }20}21    .remote(options)22    .init()23    .click('a[href="/docs/gettingstarted.html"]')24    .getTitle().then(function (title) {25        console.log('Title was: ' + title);26    })27    .elements('#search_input_react').then(function (elem) {28        console.log(elem.value[0].ELEMENT);29    })30    .end();31const webdriverio = require('webdriverio');32const options = {33    desiredCapabilities: {34    }35}36    .remote(options)37    .init()38    .click('a[href="/docs/gettingstarted.html"]')39    .getTitle().then(function (title) {40        console.log('Title was: ' + title);Using AI Code Generation
1var activeElement = browser.getActiveElement();2console.log(activeElement);3console.log(activeElement.getTagName());4var activeElement = driver.switchTo().activeElement();5console.log(activeElement);6console.log(activeElement.getTagName());Using AI Code Generation
1describe('Test', () => {2    it('should get active element', () => {3        browser.setValue('[name="q"]', 'webdriverio')4        browser.keys('Enter')5        browser.pause(3000)6        console.log(browser.getActiveElement())7    })8})9{ ELEMENT: '0.5650144002469316-1',10  'element-6066-11e4-a52e-4f735466cecf': '0.5650144002469316-1' }Using AI Code Generation
1browser.getActiveElement().then(function (activeElement) {2    console.log(activeElement.value);3});4browser.getActiveElement().then(function (activeElement) {5    console.log(activeElement.value.value);6});7browser.getActiveElement().then(function (activeElement) {8    console.log(activeElement.value.text);9});10browser.getActiveElement().then(function (activeElement) {11    console.log(activeElement.value.name);12});13browser.getActiveElement().then(function (activeElement) {14    console.log(activeElement.value.getAttribute("attributeName"));15});16browser.getActiveElement().then(function (activeElement) {17    console.log(activeElement.value.getCssValue("cssPropertyName"));18});19browser.getActiveElement().then(function (activeElement) {20    console.log(activeElement.value.getLocation());21});22browser.getActiveElement().then(function (activeElement) {23    console.log(activeElementWondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.
Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.
Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.
Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.
Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?
Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.
How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.
Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.
Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.
Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.
JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.
Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.
Get 100 minutes of automation test minutes FREE!!
