How to use client.getElementAttribute method in Appium

Best JavaScript code snippet using appium

appium-ios-tests.js

Source:appium-ios-tests.js Github

copy

Full Screen

...39 it('should find the home page text `Step One`', async function () {40 this.timeout(500000);41 client.setImplicitTimeout(100000);42 const element = await client.findElement('accessibility id', 'Step One');43 await client.getElementAttribute(element.ELEMENT, 'visible').then((attr) => {44 assert.equal(attr, 'true');45 });46 });47 it('should find the toggle element and toggle it', async function () {48 this.timeout(500000);49 client.setImplicitTimeout(100000);50 const element = await client.findElement('accessibility id', 'toggle');51 await client.getElementAttribute(element.ELEMENT, 'value').then((attr) => {52 assert.equal(attr, '0');53 });54 await client.elementClick(element.ELEMENT);55 await client.getElementAttribute(element.ELEMENT, 'value').then((attr) => {56 assert.equal(attr, '1');57 });58 });59 it('should find the search button, click it, and verify the search text `Select Country`', async function () {60 this.timeout(500000);61 client.setImplicitTimeout(100000);62 const element = await client.findElement('accessibility id', 'searchButton');63 await client.elementClick(element.ELEMENT);64 client.setImplicitTimeout(30000);65 const search_screen_element = await client.findElement('accessibility id', 'Select Country');66 await client.getElementAttribute(search_screen_element.ELEMENT, 'visible').then((attr) => {67 assert.equal(attr, 'true');68 });69 });70 it('should find the search button, click it, and return to the home page', async function () {71 this.timeout(500000);72 client.setImplicitTimeout(100000);73 const element = await client.findElement('accessibility id', 'searchButton');74 await client.elementClick(element.ELEMENT);75 client.setImplicitTimeout(300000);76 const search_screen_element = await client.findElement('accessibility id', 'header-back');77 await client.elementClick(search_screen_element.ELEMENT);78 client.setImplicitTimeout(300000);79 const home_screen_element = await client.findElement('accessibility id', 'toggle');80 await client.getElementAttribute(home_screen_element.ELEMENT, 'value').then((attr) => {81 assert.equal(attr, '0');82 });83 });84 it('should find the search button, click it, and find the first 3 countries listed', async function () {85 this.timeout(500000);86 client.setImplicitTimeout(100000);87 const element = await client.findElement('accessibility id', 'searchButton');88 await client.elementClick(element.ELEMENT);89 client.setImplicitTimeout(30000);90 const list_Item_Afghanistan = await client.findElement('accessibility id', 'listItem-Afghanistan');91 await client.getElementAttribute(list_Item_Afghanistan.ELEMENT, 'visible').then((attr) => {92 assert.equal(attr, 'true');93 });94 const list_Item_Albania = await client.findElement('accessibility id', 'listItem-Albania');95 await client.getElementAttribute(list_Item_Albania.ELEMENT, 'visible').then((attr) => {96 assert.equal(attr, 'true');97 });98 const list_Item_Algeria = await client.findElement('accessibility id', 'listItem-Algeria');99 await client.getElementAttribute(list_Item_Algeria.ELEMENT, 'visible').then((attr) => {100 assert.equal(attr, 'true');101 });102 });103 it('should find the search button, click it, enter `United States`, and verify the search box value as `United States`', async function () {104 this.timeout(500000);105 client.setImplicitTimeout(100000);106 const element = await client.findElement('accessibility id', 'searchButton');107 await client.elementClick(element.ELEMENT);108 client.setImplicitTimeout(30000);109 const search_screen_element = await client.findElement('accessibility id', 'countriesAutocompleteInput');110 await client.elementClick(search_screen_element.ELEMENT);111 await client.elementSendKeys(search_screen_element.ELEMENT, 'United States');112 client.setImplicitTimeout(30000);113 await client.getElementAttribute(search_screen_element.ELEMENT, 'value').then((attr) => {114 assert.equal(attr, 'United States');115 });116 const list_Item_United_States = await client.findElement('accessibility id', 'listItem-United States');117 await client.getElementAttribute(list_Item_United_States.ELEMENT, 'visible').then((attr) => {118 assert.equal(attr, 'true');119 });120 });121 it('should find the search bar after attempting to search again', async function () {122 this.timeout(500000);123 client.setImplicitTimeout(100000);124 const element = await client.findElement('accessibility id', 'searchButton');125 await client.elementClick(element.ELEMENT);126 client.setImplicitTimeout(30000);127 const search_screen_element = await client.findElement('accessibility id', 'countriesAutocompleteInput');128 await client.elementClick(search_screen_element.ELEMENT);129 await client.elementSendKeys(search_screen_element.ELEMENT, 'United States');130 client.setImplicitTimeout(30000);131 await client.getElementAttribute(search_screen_element.ELEMENT, 'value').then((attr) => {132 assert.equal(attr, 'United States');133 });134 const list_Item_United_States = await client.findElement('accessibility id', 'listItem-United States');135 await client.getElementAttribute(list_Item_United_States.ELEMENT, 'visible').then((attr) => {136 assert.equal(attr, 'true');137 });138 // Extension139 const back_button_element = await client.findElement('accessibility id', 'header-back');140 await client.elementClick(back_button_element.ELEMENT);141 client.setImplicitTimeout(30000);142 const search_buttom_element = await client.findElement('accessibility id', 'searchButton');143 await client.elementClick(search_buttom_element.ELEMENT);144 client.setImplicitTimeout(30000);145 146 const search_screen_on_return_element = await client.findElement('accessibility id', 'countriesAutocompleteInput');147 await client.getElementAttribute(search_screen_on_return_element.ELEMENT, 'visible').then((attr) => {148 assert.equal(attr, 'true');149 });150 });151 it('shouldn\'t find the search bar after attempting to search again after clicking on a result', async function () {152 this.timeout(500000);153 client.setImplicitTimeout(100000);154 const element = await client.findElement('accessibility id', 'searchButton');155 await client.elementClick(element.ELEMENT);156 client.setImplicitTimeout(30000);157 const search_screen_element = await client.findElement('accessibility id', 'countriesAutocompleteInput');158 await client.elementClick(search_screen_element.ELEMENT);159 await client.elementSendKeys(search_screen_element.ELEMENT, 'United States');160 client.setImplicitTimeout(30000);161 await client.getElementAttribute(search_screen_element.ELEMENT, 'value').then((attr) => {162 assert.equal(attr, 'United States');163 });164 const list_Item_United_States = await client.findElement('accessibility id', 'listItem-United States');165 await client.getElementAttribute(list_Item_United_States.ELEMENT, 'visible').then((attr) => {166 assert.equal(attr, 'true');167 });168 // Extension169 await client.elementClick(list_Item_United_States.ELEMENT);170 client.setImplicitTimeout(30000);171 const back_button_element = await client.findElement('accessibility id', 'header-back');172 await client.elementClick(back_button_element.ELEMENT);173 client.setImplicitTimeout(30000);174 const search_buttom_element = await client.findElement('accessibility id', 'searchButton');175 await client.elementClick(search_buttom_element.ELEMENT);176 client.setImplicitTimeout(30000);177 isPresent = false;178 try {179 await client.findElement('accessibility id', 'countriesAutocompleteInput');180 assert.equal(isPresent, true);181 } catch(error) {182 assert.equal(isPresent, false);183 }184 });185 it ('shouldn\'t find the home page text `Networking How to use the Fetch API in React Native.`', async function () {186 this.timeout(500000);187 client.setImplicitTimeout(100000);188 const element = await client.findElement('accessibility id', 'Networking How to use the Fetch API in React Native.');189 await client.getElementAttribute(element.ELEMENT, 'visible').then((attr) => {190 assert.equal(attr, 'false');191 });192 });193 it ('should find the home page text `Networking How to use the Fetch API in React Native.` if scrolled to bottom', async function () {194 this.timeout(500000);195 client.setImplicitTimeout(100000);196 const element = await client.findElement('accessibility id', 'Networking How to use the Fetch API in React Native.');197 await client.execute("mobile: scroll", {direction: 'down'});198 await client.getElementAttribute(element.ELEMENT, 'visible').then((attr) => {199 assert.equal(attr, 'true');200 });201 });...

Full Screen

Full Screen

appium-android-tests.js

Source:appium-android-tests.js Github

copy

Full Screen

...48 this.retries(3)49 client.setImplicitTimeout(100000);50 // Find the home page text 'Step One'51 const element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.TextView[1]');52 await client.getElementAttribute(element.ELEMENT, 'text').then((attr) => {53 assert.equal(attr, 'Step One');54 });55 });56 it('should find the toggle element and toggle it', async function () {57 this.timeout(500000);58 this.retries(3)59 client.setImplicitTimeout(100000);60 const element = await client.findElement('class name', 'android.widget.Switch');61 await client.getElementAttribute(element.ELEMENT, 'text').then((attr) => {62 assert.equal(attr, 'OFF');63 });64 await client.elementClick(element.ELEMENT);65 await client.getElementAttribute(element.ELEMENT, 'text').then((attr) => {66 assert.equal(attr, 'ON');67 });68 });69 it('should find the search button, click it, and verify the search text `Select Country`', async function () {70 this.timeout(500000);71 this.retries(3)72 client.setImplicitTimeout(100000);73 // Click the search button74 const element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup');75 await client.elementClick(element.ELEMENT);76 client.setImplicitTimeout(30000);77 // Find the text 'Search Countries'78 const search_screen_element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.widget.EditText');79 await client.getElementAttribute(search_screen_element.ELEMENT, 'text').then((attr) => {80 assert.equal(attr, 'Search Countries');81 });82 });83 it('should find the search button, click it, and return to the home page', async function () {84 this.timeout(500000);85 this.retries(3)86 client.setImplicitTimeout(100000);87 // Find the home page text 'Step One'88 const text_element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.TextView[1]');89 await client.getElementAttribute(text_element.ELEMENT, 'text').then((attr) => {90 assert.equal(attr, 'Step One');91 });92 // Click the search button93 const element = await client.findElement('xpath', '//android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup');94 client.setImplicitTimeout(300000);95 await client.elementClick(element.ELEMENT);96 client.setImplicitTimeout(300000);97 // Click on the back arrow98 const search_screen_element = await client.findElement('xpath', '//android.widget.Button[@content-desc="Home, back"]/android.widget.ImageView');99 client.setImplicitTimeout(300000);100 await client.elementClick(search_screen_element.ELEMENT);101 client.setImplicitTimeout(300000);102 // // Find the home page toggle103 const element_on_return = await client.findElement('class name', 'android.widget.Switch');104 await client.getElementAttribute(element_on_return.ELEMENT, 'text').then((attr) => {105 assert.equal(attr, 'OFF');106 });107 });108 it('should find the search button, click it, and find the first 3 countries listed', async function () {109 this.timeout(500000);110 this.retries(3)111 client.setImplicitTimeout(100000);112 // Find the home page text 'Step One'113 const text_element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.TextView[1]');114 await client.getElementAttribute(text_element.ELEMENT, 'text').then((attr) => {115 assert.equal(attr, 'Step One');116 });117 // Click the search button118 const element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup');119 client.setImplicitTimeout(300000);120 await client.elementClick(element.ELEMENT);121 client.setImplicitTimeout(300000);122 const list_Item_Afghanistan = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.widget.TextView[2]');123 await client.getElementAttribute(list_Item_Afghanistan.ELEMENT, 'text').then((attr) => {124 assert.equal(attr, '(93) Afghanistan');125 });126 const list_Item_Albania = await client.findElement('xpath', '//android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.widget.TextView[2]');127 await client.getElementAttribute(list_Item_Albania.ELEMENT, 'text').then((attr) => {128 assert.equal(attr, '(355) Albania');129 });130 const list_Item_Algeria = await client.findElement('xpath', '//android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[3]/android.view.ViewGroup/android.widget.TextView[2]');131 await client.getElementAttribute(list_Item_Algeria.ELEMENT, 'text').then((attr) => {132 assert.equal(attr, '(213) Algeria');133 });134 client.setImplicitTimeout(300000);135 });136 it('should find the search button, click it, enter `United States`, and verify the search box value as `United States`', async function () {137 this.timeout(500000);138 this.retries(3)139 client.setImplicitTimeout(100000);140 // Find the home page text 'Step One'141 const text_element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.TextView[1]');142 await client.getElementAttribute(text_element.ELEMENT, 'text').then((attr) => {143 assert.equal(attr, 'Step One');144 });145 // Click the search button146 const element = await client.findElement('xpath', '//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup');147 client.setImplicitTimeout(300000);148 await client.elementClick(element.ELEMENT);149 client.setImplicitTimeout(300000);150 // Enter text into the search box151 const search_screen_element = await client.findElement('class name', 'android.widget.EditText');152 client.setImplicitTimeout(300000);153 await client.elementClick(search_screen_element.ELEMENT);154 client.setImplicitTimeout(300000);155 await client.elementSendKeys(search_screen_element.ELEMENT, 'United States');156 client.setImplicitTimeout(300000);157 await client.getElementAttribute(search_screen_element.ELEMENT, 'text').then((attr) => {158 assert.equal(attr, 'United States');159 });160 client.setImplicitTimeout(300000);161 // Verify the search result `United States`162 const list_Item_United_States = await client.findElement('xpath', '//android.view.ViewGroup[2]/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.TextView[2]');163 await client.getElementAttribute(list_Item_United_States.ELEMENT, 'text').then((attr) => {164 assert.equal(attr, '(1) United States');165 });166 });...

Full Screen

Full Screen

ios-basic-interactions.test.js

Source:ios-basic-interactions.test.js Github

copy

Full Screen

...28 const doneButton = await client.findElement('accessibility id', 'Done');29 await client.elementClick(doneButton.ELEMENT);30 // check profile31 const usernameText = await client.findElement('xpath', `//XCUIElementTypeStaticText[@name="${newSetProfile.username}"]`);32 const username = await client.getElementAttribute(usernameText.ELEMENT, 'value');33 assert.equal(username, newSetProfile.username);34 })35 // it('should send keys to inputs', async function () {36 // const elementId = await client.findElement('accessibility id', 'account');37 // client.elementSendKeys(elementId.ELEMENT, 'Hello World!');38 // const elementValue = await client.findElement('accessibility id', 'TextField1');39 // await client.getElementAttribute(elementValue.ELEMENT, 'value').then((attr) => {40 // assert.equal(attr, 'Hello World!');41 // });42 // });43 // it('should click a button that opens an alert', async function () {44 // const element = await client.findElement('accessibility id', 'show alert');45 // await client.elementClick(element.ELEMENT);46 // assert.equal(await client.getAlertText(), 'Cool title\nthis alert is so cool.');47 // });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...14async function main(){15 const elementId = await client.findElement("accessibility id","TextField1"); 16 client.elementSendKeys(elementId.ELEMENT, "Hello World!");17 const elementValue = await client.findElement("accessibility id","TextField1");18 await client.getElementAttribute(elementValue.ELEMENT,"value").then((attr) => {19 assert.equal(attr,"Hello World!");20 });21}22console.log('init');23main();...

Full Screen

Full Screen

ios-create-session.test.js

Source:ios-create-session.test.js Github

copy

Full Screen

...11 it('should create and destroy IOS sessions', async function () {12 const res = await client.status();13 assert.isObject(res.build);14 const element = await client.findElement('class name', 'XCUIElementTypeApplication');15 await client.getElementAttribute(element.ELEMENT, 'name').then((attr) => {16 assert.equal(attr, 'TestApp');17 });18 const destroySession = await client.deleteSession();19 assert.isNull(destroySession);20 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9 console.log("value of input field is : " + value);10});11driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3var By = webdriver.By;4var until = webdriver.until;5driver.findElement(By.name('q')).sendKeys('webdriver');6driver.findElement(By.name('btnG')).click();7driver.wait(until.titleIs('webdriver - Google Search'), 1000);8driver.findElement(By.name('btnI')).click();9driver.wait(until.titleIs('I'm Feeling Lucky'), 1000);10driver.quit();11org.openqa.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.findElement(By.name('q')).getAttribute('value').then(function(value) {10 console.log(value);11});12driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1 .init()2 .elementByAccessibilityId('test-Username').getAttribute('value').then(function(text) {3 console.log(text);4 })5 .fin(function() { return client.quit(); })6 .done();7[debug] [MJSONWP] Calling AppiumDriver.getAttribute() with args: ["test-Username","value","e5b8a5a6-1d6a-4a4e-a8b4-0d9b2a2d6a1a"]8[debug] [JSONWP Proxy] Got response with status 200: "{\n \"value\" : \"\",\n \"sessionId\" : \"5B6E5D6A-0B60-4B9B-9A3A-2B4C4D0F7C1B\",\n \"status\" : 0\n}"9[debug] [MJSONWP] Responding to client with driver.getAttribute() result: ""10info: Welcome to Appium v1.6.4 (REV 0c1b7e1c4d8e9d3d3e3e2b4f4c4f4d4b4c4f4d4b)

Full Screen

Using AI Code Generation

copy

Full Screen

1var id = client.getElementAttribute("id");2console.log(id);3var text = client.getText();4console.log(text);5var isDisplayed = client.isDisplayed();6console.log(isDisplayed);7var location = client.getLocation();8console.log(location);9var size = client.getSize();10console.log(size);11client.clear();12var isKeyboardShown = client.isKeyboardShown();13console.log(isKeyboardShown);14client.hideKeyboard();15var orientation = client.getOrientation();16console.log(orientation);17client.setOrientation("LANDSCAPE");18var alertText = client.getAlertText();19console.log(alertText);20client.setAlertText("This is a test alert");21client.acceptAlert();22client.dismissAlert();23var deviceTime = client.getDeviceTime();24console.log(deviceTime);25var geoLocation = client.getGeoLocation();26console.log(geoLocation);27client.setGeoLocation("40.714224", "-73.961452");28var networkConnection = client.getNetworkConnection();29console.log(networkConnection);30client.setNetworkConnection(6);31var performanceData = client.getPerformanceData("com.example.android.apis", "memoryinfo", 10);32console.log(performanceData);33var performanceDataTypes = client.getPerformanceDataTypes();34console.log(performanceDataTypes);

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('webdriverio').remote({2 desiredCapabilities: {3 }4});5 .init()6 .setValue('*[name="q"]','webdriverio')7 .click('*[name="btnG"]')8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .getAttribute('*[name="btnG"]', 'value').then(function(value) {12 console.log('The value of the button is: ' + value);13 })14 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var el = client.findElement("id", "com.abc.myapp:id/elementID");2el.getAttribute("text").then(function(text) {3 console.log(text);4});5client.getElementAttribute("id", "com.abc.myapp:id/elementID", "text").then(function(text) {6 console.log(text);7});8client.getElementAttribute("id", "com.abc.myapp:id/elementID", "text").then(function(text) {9 console.log(text);10});

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 automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful