How to use driver.FindElementById method in Appium

Best JavaScript code snippet using appium

Run Appium automation tests on LambdaTest cloud grid

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

LoginStepDefinitions.js

Source: LoginStepDefinitions.js Github

copy
1import { When, Then, After,Given } from '@cucumber';
2import assert from 'assert';
3import {Builder} from 'selenium-webdriver';
4
5Given('realizo login na Smarttbot', async function () {
6    this.driver = new Builder()
7        .forBrowser('chrome')
8        .setChromeOptions('disable-infobars')
9        .build();
10
11        this.driver.get('https://app.smarttbot.com/public/login');
12
13   await this.driver.findElementById("login-username").sendkeys("[email protected]");
14   await this.driver.findElementById("login-password").sendkeys("[email protected]");
15   await this.driver.findElementById("login-button").click();
16});
17
18When('Clico em "estratégia" no menu lateral', async function(){
19    await this.driver.findElementById("sidebar-menu-item-scoreboard").click();
20});
21
22After(async function() {
23    this.driver.close();
24});
Full Screen

report.js

Source: report.js Github

copy
1$(document).ready(function() {var formatter = new CucumberHTML.DOMFormatter($('.cucumber-report'));formatter.uri("features/smallcaseAssignment.feature");
2formatter.feature({
3  "name": "Two compare price offered for product in two different shopping sites i.e. Flipkart.com and Amazon.com",
4  "description": "",
5  "keyword": "Feature"
6});
7formatter.scenario({
8  "name": "Open Flipkart.com and Amazon.in and compare the the price of an product",
9  "description": "",
10  "keyword": "Scenario"
11});
12formatter.before({
13  "status": "passed"
14});
15formatter.step({
16  "name": "Launch the chrome browser in mobile",
17  "keyword": "Given "
18});
19formatter.match({
20  "location": "ComparePriceSteps.launch_the_chrome_browser_in_mobile()"
21});
22formatter.result({
23  "status": "passed"
24});
25formatter.step({
26  "name": "open Flipkart site from search box",
27  "keyword": "When "
28});
29formatter.match({
30  "location": "ComparePriceSteps.open_flipkat_com_from_search_box(String)"
31});
32formatter.result({
33  "status": "passed"
34});
35formatter.step({
36  "name": "search for the product VU TV in flipkart.com",
37  "keyword": "And "
38});
39formatter.match({
40  "location": "ComparePriceSteps.search_for_the_product_vu_tv()"
41});
42formatter.result({
43  "status": "passed"
44});
45formatter.step({
46  "name": "note the price and product name",
47  "keyword": "And "
48});
49formatter.match({
50  "location": "ComparePriceSteps.noteThePriceAndProductName()"
51});
52formatter.result({
53  "status": "passed"
54});
55formatter.step({
56  "name": "open Amazon site from search box",
57  "keyword": "And "
58});
59formatter.match({
60  "location": "ComparePriceSteps.open_flipkat_com_from_search_box(String)"
61});
62formatter.result({
63  "status": "passed"
64});
65formatter.step({
66  "name": "search for the product VU TV in amazon.com",
67  "keyword": "And "
68});
69formatter.match({
70  "location": "ComparePriceSteps.searchForTheProductVUTVInAmazonCom()"
71});
72formatter.result({
73  "error_message": "org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {message\u003dunknown error: unknown sessionId\n  (Session info: chrome\u003d84.0.4147.125)\n  (Driver info: chromedriver\u003d2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85),platform\u003dMac OS X 10.15.2 x86_64)}\nBuild info: version: \u00273.141.59\u0027, revision: \u0027e82be7d358\u0027, time: \u00272018-11-14T08:17:03\u0027\nSystem info: host: \u0027PasannaD-MBA\u0027, ip: \u0027fe80:0:0:0:c0f:64a5:424d:9c9d%en0\u0027, os.name: \u0027Mac OS X\u0027, os.arch: \u0027x86_64\u0027, os.version: \u002710.15.2\u0027, java.version: \u00271.8.0_181\u0027\nDriver info: driver.version: AndroidDriver\n\tat org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:333)\n\tat io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)\n\tat io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)\n\tat io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)\n\tat org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)\n\tat io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:69)\n\tat io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)\n\tat io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)\n\tat org.openqa.selenium.By$ById.findElement(By.java:188)\n\tat org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)\n\tat io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)\n\tat io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)\n\tat io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)\n\tat com.sc.pages.AmazonObjects.searchForTheProduct(AmazonObjects.java:29)\n\tat com.sc.stepDef.ComparePriceSteps.searchForTheProductVUTVInAmazonCom(ComparePriceSteps.java:53)\n\tat ✽.search for the product VU TV in amazon.com(features/smallcaseAssignment.feature:11)\nCaused by: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to org.openqa.selenium.WebElement\n\tat org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:331)\n\tat io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)\n\tat io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)\n\tat io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)\n\tat org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)\n\tat io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:69)\n\tat io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)\n\tat io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)\n\tat org.openqa.selenium.By$ById.findElement(By.java:188)\n\tat org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)\n\tat io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)\n\tat io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)\n\tat io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)\n\tat com.sc.pages.AmazonObjects.searchForTheProduct(AmazonObjects.java:29)\n\tat com.sc.stepDef.ComparePriceSteps.searchForTheProductVUTVInAmazonCom(ComparePriceSteps.java:53)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat cucumber.runtime.Utils$1.call(Utils.java:40)\n\tat cucumber.runtime.Timeout.timeout(Timeout.java:16)\n\tat cucumber.runtime.Utils.invoke(Utils.java:34)\n\tat cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)\n\tat cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)\n\tat cucumber.api.TestStep.executeStep(TestStep.java:78)\n\tat cucumber.api.TestStep.run(TestStep.java:61)\n\tat cucumber.api.TestCase.run(TestCase.java:28)\n\tat cucumber.runner.Runner.runPickle(Runner.java:80)\n\tat cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)\n\tat cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)\n\tat cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)\n\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n\tat cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)\n\tat cucumber.api.junit.Cucumber.runChild(Cucumber.java:99)\n\tat cucumber.api.junit.Cucumber.runChild(Cucumber.java:41)\n\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n\tat cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:108)\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n\tat org.junit.runner.JUnitCore.run(JUnitCore.java:137)\n\tat com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)\n\tat com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)\n",
74  "status": "failed"
75});
76formatter.step({
77  "name": "check for the price and product name",
78  "keyword": "And "
79});
80formatter.match({
81  "location": "ComparePriceSteps.checkForThePriceAndProductName()"
82});
83formatter.result({
84  "status": "skipped"
85});
86formatter.step({
87  "name": "Compare the Price between two different sites for same product",
88  "keyword": "Then "
89});
90formatter.match({
91  "location": "ComparePriceSteps.compareThePriceBetweenTwoDifferentSitesForSameProduct()"
92});
93formatter.result({
94  "status": "skipped"
95});
96formatter.after({
97  "status": "passed"
98});
99});
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

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

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

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

Test now for Free
LambdaTestX

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

Allow Cookie
Sarah

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

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

Sarah Elson (Product & Growth Lead)