10 examples of 'javascript get element by css selector multiple' in JavaScript

Every line of 'javascript get element by css selector multiple' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
247function elementByCssExists(selector, delay = 2000) {
248 return driver.waitForElementByCss(selector, delay)
249 .should.eventually.exist;
250}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

25function findElement(selectors) {
26 let currentElement = document;
27 for (let i = 0; i < selectors.length; i++) {
28 if (i > 0) {
29 currentElement = currentElement.shadowRoot;
30 }
31
32 currentElement = currentElement.querySelector(selectors[i]);
33
34 if (!currentElement) {
35 break;
36 }
37 }
38
39 return currentElement;
40}
347async findAllByCssSelector(selector, timeout = defaultFindTimeout) {
348 this.debug('in findAllByCssSelector: ' + selector);
349 const remote = this.remote.setFindTimeout(timeout);
350 let elements = await remote.findAllByCssSelector(selector);
351 this.remote.setFindTimeout(defaultFindTimeout);
352 if (!elements) elements = [];
353 this.debug(`Found ${elements.length} for selector ${selector}`);
354 return elements;
355}
15function get(selector) { return document.querySelector(selector) || document.getElementById(selector) }
44function bySelectorAll(selector) {
45 return document.querySelectorAll(selector);
46}
29function getValue(selector) {
30 return browser.executeScript(`
31 return $('${selector}').val();
32 `);
33}
15public findElement(selector: string): WebElementPromise {
16 return this.driver.findElement(By.css(selector));
17}
143function getSelectorValue(selectorId) {
144 var resource = document.getElementById(selectorId);
145 log("selector "+resource.name);
146 var myIndex = resource.selectedIndex;
147 log("index: " +myIndex);
148 log(resource.options);
149 log(resource.options[myIndex].value);
150 return resource.options[myIndex].value
151}
34function selector(element) {
35 var target = element;
36
37 if (typeof target === 'string') {
38 target = document.querySelector(target);
39 }
40
41 return target;
42}
173export function clickElementByXPath(driver: WebDriver, xpath: string) {
174 return retry(5, driver, async function(driver, count) {
175 if (count>1 && config.LOG_DETAILS) console.log("clickElementByXPath ",xpath," attempt #",count);
176 let elem = await shadowRoot(driver);
177 elem = await findByXPath(elem, xpath);
178 await elem.click();
179 });
180 // Stale element possible:
181 // return to(driver.findElement(By.xpath(xpath)).click());
182}

Related snippets