How to use driver.findNativeElementOrElements method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

gesture.js

Source:gesture.js Github

copy

Full Screen

...12 return el ? util.unwrapElement(el) : null;13}14async function toElementOrApplicationId (driver, opts = {}) {15 return toElementId(opts)16 || util.unwrapElement(await driver.findNativeElementOrElements(`class name`, `XCUIElementTypeApplication`, false));17}18commands.moveTo = async function moveTo (el, xoffset = 0, yoffset = 0) {19 el = util.unwrapElement(el);20 if (this.isWebContext()) {21 let {x, y} = await this.getLocation(el);22 let coords = {23 x: x + xoffset,24 y: y + yoffset25 };26 this.curWebCoords = coords;27 let atomsElement = this.getAtomsElement(el);28 let relCoords = {x: xoffset, y: yoffset};29 await this.executeAtom('move_mouse', [atomsElement, relCoords]);30 } else {...

Full Screen

Full Screen

certificate.js

Source:certificate.js Github

copy

Full Screen

...119 } = options;120 const lookupDelay = 500;121 try {122 element = await retryInterval(timeout < lookupDelay ? 1 : timeout / lookupDelay, lookupDelay,123 () => driver.findNativeElementOrElements(locator.type, locator.value, false)124 );125 } catch (err) {126 if (skipIfInvisible) {127 return false;128 }129 throw new Error(`Cannot find ${JSON.stringify(locator)} within ${timeout}ms timeout`);130 }131 await driver.nativeClick(element);132 return true;133}134async function installPre122Certificate (driver) {135 // Accept Safari alert136 await clickElement(driver, Button.Allow, {137 // certificate load might take some time on slow machines138 timeout: 15000,139 });140 // Wait until Preferences are opened141 await B.delay(2000);142 // Go through Preferences wizard143 if (!await clickElement(driver, Button.Install, {144 skipIfInvisible: true,145 })) {146 return false;147 }148 // We need to click Install button on two different tabs149 // The second one confirms the previous150 await B.delay(1500);151 await clickElement(driver, Button.Install);152 // Accept alert153 await clickElement(driver, Alert.Install);154 // Finish adding certificate155 await clickElement(driver, Button.Done);156 return true;157}158async function trustCertificateInPreferences (driver, name) {159 await clickElement(driver, Settings.General);160 await clickElement(driver, Settings.About);161 const switchLocator = {162 type: '-ios class chain',163 value: `**/XCUIElementTypeCell[\`label == '${name}'\`]/**/XCUIElementTypeSwitch`,164 };165 await retry(5, async () => {166 await driver.mobileSwipe({167 element: await driver.findNativeElementOrElements('class name', 'XCUIElementTypeTable', false),168 direction: 'up'169 });170 await clickElement(driver, Settings.Certificate_Trust_Settings, {171 timeout: 500,172 });173 await driver.findNativeElementOrElements(switchLocator.type, switchLocator.value, false);174 });175 // Only click the switch if it is set to Off176 if (await clickElement(driver, {177 type: switchLocator.type,178 value: `${switchLocator.value}[\`value == '0'\`]`179 }, {180 timeout: 1000,181 skipIfInvisible: true,182 })) {183 await driver.postAcceptAlert();184 }185}186async function installPost122Certificate (driver, name) {187 // Accept Safari alert188 await clickElement(driver, Button.Allow, {189 // certificate load might take some time on slow machines190 timeout: 15000,191 });192 // Wait for the second alert193 await B.delay(2000);194 await driver.postAcceptAlert();195 await driver.activateApp('com.apple.Preferences');196 await clickElement(driver, Settings.General);197 await clickElement(driver, Settings.Profile);198 // Select the target cert199 let isCertFound = false;200 for (let swipeNum = 0; swipeNum < 5; ++swipeNum) {201 if (await clickElement(driver, {202 type: '-ios class chain',203 value: `**/XCUIElementTypeCell[\`label == '${name}'\`]`,204 }, {205 timeout: 500,206 skipIfInvisible: true,207 })) {208 isCertFound = true;209 break;210 }211 await driver.mobileSwipe({212 element: await driver.findNativeElementOrElements('class name', 'XCUIElementTypeTable', false),213 direction: 'up'214 });215 }216 if (!isCertFound) {217 throw new Error(`'${name}' cannot be found in the certificates list`);218 }219 // Install option is only visible if the cert is not installed yet220 if (!await clickElement(driver, Button.Install, {221 skipIfInvisible: true,222 })) {223 return false;224 }225 await B.delay(1500);226 // Confirm untrusted cert install...

Full Screen

Full Screen

web.js

Source:web.js Github

copy

Full Screen

...125 if (!text) {126 text = await driver.executeAtom('get_attribute_value', [atomsElement, 'value']);127 }128 if (text) {129 const els = await driver.findNativeElementOrElements('accessibility id', text, true);130 if (els.length === 1 || els.length === 2) {131 const el = els[0];132 // use tap because on iOS 11.2 and below `nativeClick` crashes WDA133 const rect = await driver.proxyCommand(`/element/${util.unwrapElement(el)}/rect`, 'GET');134 if (els.length === 2) {135 const el2 = els[1];136 const rect2 = await driver.proxyCommand(`/element/${util.unwrapElement(el2)}/rect`, 'GET');137 if ((rect.x !== rect2.x || rect.y !== rect2.y) ||138 (rect.width !== rect2.width || rect.height !== rect2.height)) {139 // These 2 native elements are not referring to the same web element140 return false;141 }142 }143 const coords = {...

Full Screen

Full Screen

find-specs.js

Source:find-specs.js Github

copy

Full Screen

...8 });9 describe('findNativeElementOrElements', function () {10 async function verifyFind (strategy, selector, modSelector, modStrategy = null, mult = false) {11 try {12 await driver.findNativeElementOrElements(strategy, selector, mult);13 } catch (ign) {}14 proxySpy.calledOnce.should.be.true;15 proxySpy.firstCall.args[0].should.eql(`/element${mult ? 's' : ''}`);16 proxySpy.firstCall.args[1].should.eql('POST');17 proxySpy.firstCall.args[2].should.eql({18 using: modStrategy || strategy,19 value: modSelector20 });21 proxySpy.reset();22 }23 it('should convert class names from UIA to XCUI', async function () {24 await verifyFind('class name', 'UIAButton', 'XCUIElementTypeButton');25 await verifyFind('class name', 'UIAMapView', 'XCUIElementTypeMap');26 await verifyFind('class name', 'UIAScrollView', 'XCUIElementTypeScrollView');27 await verifyFind('class name', 'UIACollectionView', 'XCUIElementTypeCollectionView');28 await verifyFind('class name', 'UIATextView', 'XCUIElementTypeTextView');29 await verifyFind('class name', 'UIAWebView', 'XCUIElementTypeWebView');30 });31 it('should convert xpaths from UIA to XCUI', async function () {32 await verifyFind('xpath', '//UIAButton', '//XCUIElementTypeButton');33 await verifyFind('xpath',34 '//UIAButton/UIATextField',35 '//XCUIElementTypeButton/XCUIElementTypeTextField');36 await verifyFind('xpath',37 'UIAButton//UIATextField',38 'XCUIElementTypeButton//XCUIElementTypeTextField');39 await verifyFind('xpath',40 '//UIAButton[@name="foo"]',41 '//XCUIElementTypeButton[@name="foo"]');42 await verifyFind('xpath',43 '//UIAButton/Weird',44 '//XCUIElementTypeButton/Weird');45 await verifyFind('xpath',46 '//UIAMapView/UIAScrollView',47 '//XCUIElementTypeMap/XCUIElementTypeScrollView');48 await verifyFind('xpath',49 '//UIAMapView/UIAScrollView[@name="UIADummyData"]',50 '//XCUIElementTypeMap/XCUIElementTypeScrollView[@name="UIADummyData"]');51 await verifyFind('xpath',52 '//XCUIElementTypeMap[@name="UIADummyData"]',53 '//XCUIElementTypeMap[@name="UIADummyData"]');54 });55 it('should reject request for first visible child with no context', async function () {56 await driver.findNativeElementOrElements(57 'xpath', '/*[@firstVisible="true"]', false)58 .should.eventually.be.rejectedWith(/without a context element/);59 });60 it('should reject request for multiple first visible children', async function () {61 await driver.findNativeElementOrElements(62 'xpath', '/*[@firstVisible="true"]', true)63 .should.eventually.be.rejectedWith(/Cannot get multiple/);64 });65 it('should convert magic first visible child xpath to class chain', async function () {66 const variants = [67 '/*[@firstVisible="true"]',68 "/*[@firstVisible='true']",69 "/*[@firstVisible = 'true']"70 ];71 let attribSpy = sinon.stub(driver, 'getAttribute');72 for (const variant of variants) {73 proxySpy.withArgs(74 '/element/ctx/element',75 'POST',76 {using: 'class chain', value: '*[1]'}77 ).returns({ELEMENT: 1});78 proxySpy.withArgs(79 '/element/ctx/element',80 'POST',81 {using: 'class chain', value: '*[2]'}82 ).returns({ELEMENT: 2});83 attribSpy.withArgs('visible', {ELEMENT: 1}).returns('false');84 attribSpy.withArgs('visible', {ELEMENT: 2}).returns('true');85 let el = await driver.findNativeElementOrElements('xpath',86 variant, false, {ELEMENT: 'ctx'});87 proxySpy.calledTwice.should.be.true;88 proxySpy.firstCall.args[2].should.eql({89 using: 'class chain',90 value: '*[1]',91 });92 proxySpy.secondCall.args[2].should.eql({93 using: 'class chain',94 value: '*[2]',95 });96 attribSpy.calledTwice.should.be.true;97 el.should.eql({ELEMENT: 2});98 proxySpy.reset();99 attribSpy.reset();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2 .withCapabilities({3 })4 .build();5driver.findNativeElementOrElements('accessibility id', 'button', function(err, element) {6 if (err) throw err;7 element.click();8});9driver.findNativeElementOrElements('class name', 'XCUIElementTypeButton', function(err, element) {10 if (err) throw err;11 element.click();12});13driver.findNativeElementOrElements('predicate string', 'label == "button"', function(err, element) {14 if (err) throw err;15 element.click();16});17driver.findNativeElementOrElements('name', 'button', function(err, element) {18 if (err) throw err;19 element.click();20});21 if (err) throw err;22 element.click();23});24driver.findNativeElementOrElements('class chain', '**/XCUIElementTypeButton[`label == "button"`]', function(err, element) {25 if (err) throw err;26 element.click();27});28driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5 .forBrowser('selenium')6 .build();7driver.findElement(By.name('Get Started')).click();8driver.wait(until.elementLocated(By.name('Log in')), 5000);9driver.findElement(By.name('Log in')).click();10driver.wait(until.elementLocated(By.name('Email')), 5000);11driver.findElement(By.name('Email')).sendKeys('

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var desired = require('./desired');3var assert = require('assert');4var By = webdriver.By;5var serverConfig = {6};7var driver = new webdriver.Builder()8 .withCapabilities(desired)9 .build();10driver.initSession().then(function () {11 return driver.findNativeElementOrElements('class name', 'XCUIElementTypeButton', false);12}).then(function (elements) {13 console.log('Found ' + elements.length + ' buttons');14 assert.equal(elements.length, 1);15}).quit();16module.exports = {17};18Xcode 8.0 (8A218a)19Xcode 8.1 (8B62)20Xcode 8.2 (8C38)21Xcode 8.2.1 (8C1002)22Xcode 8.3 (8E162)23Xcode 8.3.1 (8E1000a)24Xcode 8.3.2 (8E200

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new iosDriver({2});3 .init()4 .then(function () {5 return driver.findNativeElementOrElements('class chain', '**/XCUIElementTypeWindow[`name == "MyWindow"`]', false);6 })7 .then(function (element) {8 return element.click();9 })10 .then(function () {11 return driver.quit();12 });13var driver = new androidDriver({14});15 .init()16 .then(function () {17 return driver.findNativeElementOrElements('class chain', '**/android.widget.TextView[`name == "MyTextView"`]', false);18 })19 .then(function (element) {20 return element.click();21 })22 .then(function () {23 return driver.quit();24 });25var driver = new androidDriver({26});27 .init()28 .then(function () {29 return driver.findNativeElementOrElements('class chain', '**/android.widget.TextView[`name == "MyTextView"`]', false);30 })31 .then(function (element) {32 return element.click();33 })34 .then(function () {35 return driver.quit();36 });37var driver = new windowsDriver({38});39 .init()40 .then(function () {

Full Screen

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.support.ui.WebDriverWait;7import org.openqa.selenium.support.ui.ExpectedConditions;8import java.net.URL;9import java.util.List;10public class test {11 public static void main(String[] args) throws Exception {12 DesiredCapabilities capabilities = new DesiredCapabilities();13 capabilities.setCapability("platformName", "iOS");14 capabilities.setCapability("platformVersion", "10.2");15 capabilities.setCapability("deviceName", "iPhone 6");16 capabilities.setCapability("app", "/Users/tester/Library/Developer/Xcode/DerivedData/test-awfvhjyjxqjyqjgqjzqjxqfjwzef/Build/Products/Debug-iphonesimulator/test.app");17 capabilities.setCapability("automationName", "XCUIT

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2 .forBrowser('safari')3 .build();4 .then(function (el) {5 el.click();6 });7driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const { exec } = require('child_process');5const PORT = 4723;6const HOST = 'localhost';7const DEFAULT_CAPS = {8};9const DEFAULT_TIMEOUT = 60000;10const DEFAULT_INTERVAL = 1000;11const DEFAULT_IMPLICIT_TIMEOUT = 10000;12chai.should();13chai.use(chaiAsPromised);14describe('Native element search', () => {15 let driver;16 let allPassed = true;17 let caps;18 before(async () => {19 driver = wd.promiseChainRemote(HOST, PORT);20 caps = Object.assign({}, DEFAULT_CAPS);21 await driver.init(caps);22 await driver.setImplicitWaitTimeout(DEFAULT_IMPLICIT_TIMEOUT);23 });24 after(async () => {25 await driver.quit();26 });27 afterEach(function () {28 allPassed = allPassed && (this.currentTest.state === 'passed');29 });30 it('should find native element', async () => {31 const element = await driver.findNativeElementOrElements('id', 'id_of_the_element', false);32 element.should.exist;33 });34 it('should find multiple native elements', async () => {35 const elements = await driver.findNativeElementOrElements('id', 'id_of_the_element', true);36 elements.should.exist;37 elements.length.should.be.above(1);38 });39});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful