Best io.appium code snippet using io.appium.java_client.AppiumBy.findElement
AppiumAppTest.java
Source:AppiumAppTest.java
...40 WebElement element = null;41 String currentPageText = new String();42 try {43 // tek erisim elemani xpath oldugundan onu kullandik, tavsiye edilmez44 element = driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.view.ViewGroup/android.widget.TextView"));45 currentPageText = element.getText();46 if (currentPageText.equalsIgnoreCase("anasayfa"))47 System.out.println("Anasayfa Testi Basarili");48 else49 System.out.println("Anasayfa Testi Basarisiz");50 } catch (Exception e) {51 System.err.println("Anasayfa Yazisi Bulunamadi");52 }53 }54 /** // 2.1. Test: Anasayfa slayt // 2.2 Bilgi Yazisi */55 public void test2() {56 57 if(!this.isConnected()) {58 System.err.println("Once server'a baglanin lutfen");59 return;60 }61 Actions actions = new Actions(driver);62 WebElement element = null;63 try {64 element = driver.findElement(AppiumBy.accessibilityId("Slayt"));65 String elementClass = element.getAttribute("class");66 if (elementClass.equalsIgnoreCase("android.widget.imageview")) {67 System.out.println("Slayt Bulundu, Butonlar Deneniyor...");68 try {69 WebElement btn = driver.findElement(AppiumBy.id("com.example.myapp:id/btnSlideLeft"));70 if (btn.getAttribute("clickable").equalsIgnoreCase("True")) {71 actions.moveToElement(btn).click().perform();72 System.out.println("Sol Buton Calisiyor");73 } else {74 System.out.println("Sol Buton Calismiyor");75 }76 btn = driver.findElement(AppiumBy.id("com.example.myapp:id/btnSlideRight"));77 if (btn.getAttribute("clickable").equalsIgnoreCase("True")) {78 actions.moveToElement(btn).click().perform();79 System.out.println("Sag Buton Calisiyor");80 } else {81 System.out.println("Sag Buton Calismiyor");82 }83 } catch (Exception e) {84 System.out.println("Butonlar bulunurken hata");85 }86 }87 } catch (Exception e) {88 System.err.println("Anasayfa Slayti bulunamadi");89 } 90 91 try {92 element = driver.findElement(AppiumBy.id("com.example.myapp:id/tvMainAbout"));93 String text = "Bölümümüzün misyonu Bilgisayar MühendisliÄi alanında bilgi "94 + "ve teknoloji üretmek, üretilen deÄerleri medeniyetlerin "95 + "ilerlemesi için kullanmak, ve yenilikçi ve araÅtırma eksenli "96 + "bir eÄitim vererek kendine güvenen, giriÅimci, eleÅtirel analiz "97 + "yapabilen, teknik ve etik bilgilerle donatılmıÅ, bilgisayar yazılım, "98 + "donanım ve bilgi sistemleri tasarlayabilen, geliÅtirebilen ve "99 + "sürdürebilen mühendisler yetiÅtirmektir.";100 101 if(element.getAttribute("text").equals(text)) {102 System.out.println("Bilgi yazisi dogru bir sekilde bulundu.");103 System.out.println("Yazi sinirlari: " + element.getAttribute("bounds"));104 }105 } catch (Exception e) {106 System.err.println("Bilgi Yazisi Bulunamadi");107 }108 }109 110 /** //open dropdown */111 public void test3a() {112 if(!this.isConnected()) {113 System.err.println("Once server'a baglanin lutfen");114 return;115 }116 WebElement element = null;117 try {118 System.out.println("Dropdown acilisi test ediliyor...");119 element = driver.findElement(AppiumBy.accessibilityId("Open navigation"));120 element.click();121 System.out.println("Dropdown aciliyor.");122 } catch (Exception e) {123 System.err.println("Dropdown Acilmiyor.");124 }125 }126 /** /close dropdown */127 public void test3b() {128 if(!this.isConnected()) {129 System.err.println("Once server'a baglanin lutfen");130 return;131 }132 WebElement element = null;133 try {134 System.out.println("Dropdown kapanisi test ediliyor...");135 element = driver.findElement(AppiumBy.accessibilityId("Close navigation"));136 element.click();137 System.out.println("Dropdown kapaniyor.");138 } catch (Exception e) {139 System.err.println("Dropdown Kapanmiyor.");140 }141 }142 /**143 //urun secenekleri144 //dropdown acmadan kullanmayin145 */146 public void test4() {147 if(!this.isConnected()) {148 System.err.println("Once server'a baglanin lutfen");149 return;150 }151 WebElement urun1 = null;152 WebElement urun2 = null;153 try { 154 System.out.println("Urunler kontrol ediliyor...");155 //yetiskin urun156 urun1 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductAdult"));157 158 if(urun1.getAttribute("clickable").equalsIgnoreCase("true"))159 System.out.println("Yetiskin urunleri bulundu");160 161 urun2 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductChild"));162 if(urun2.getAttribute("clickable").equalsIgnoreCase("true"))163 System.out.println("Cocuk urunleri bulundu");164 165 System.out.println("Urun secenekleri basarili.");166 } catch (Exception e) {167 System.err.println("Urunler Sekmesi Elemanlari Yetersiz ya da Bulunamadi");168 }169 }170 /**171 yetiskin urun sayfa sol-sag butonlari172 dropdown acmadan kullanmayin173 */174 public void test5a() {175 WebElement adltBtnLeft = null;176 WebElement adltBtnRight = null;177 WebElement urun1 = null;178 try {179 urun1 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductAdult"));180 urun1.click();181 System.out.println("Yetiskin butonlari deneniyor...");182 try {183 adltBtnRight = driver.findElement(AppiumBy.id("com.example.myapp:id/btnRight"));184 for (int i = 0; i < 6; i++) {185 adltBtnRight.click();186 }187 188 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten son sayfadasınız."))189 System.out.println("Ileri buton calisiyor");190 191 192 } catch (Exception e) {193 System.err.println("Ileri butonu bulunurken hata");194 }195 System.out.println("Geri butonu bekleniyor");196 try { 197 Thread.sleep(5000);198 adltBtnLeft = driver.findElement(AppiumBy.id("com.example.myapp:id/btnLeft"));199 200 for (int i = 0; i < 6; i++) {201 adltBtnLeft.click();202 }203 204 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten ilk sayfadasınız."))205 System.out.println("Geri buton calisiyor");206 207 } catch (Exception e) {208 System.err.println("Geri buton bulunurken hata");209 }210 } catch (Exception e) {211 System.err.println("Yetiskin ekranina gidilemedi");212 }213 }214 /**215 cocuk urun sayfa sol-sag butonlari216 dropdown acmadan kullanmayin217 */218 public void test5b() {219 WebElement urun2 = null;220 WebElement chldBtnLeft = null;221 WebElement chldBtnRight = null;222 try {223 urun2 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductChild"));224 urun2.click();225 System.out.println("Cocuk butonlari deneniyor...");226 try {227 chldBtnLeft = driver.findElement(AppiumBy.id("com.example.myapp:id/btnLeftChild"));228 chldBtnRight = driver.findElement(AppiumBy.id("com.example.myapp:id/btnRightChild"));229 230 for (int i = 0; i < 6; i++) {231 chldBtnRight.click();232 }233 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten son sayfadasınız."))234 System.out.println("Ileri buton calisiyor");235 } catch (Exception e) {236 System.err.println("Ileri butonu bulunurken hata");237 }238 System.out.println("Geri butonu bekleniyor");239 try {240 Thread.sleep(5000);241 for (int i = 0; i < 6; i++) {242 chldBtnLeft.click();243 }244 245 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten ilk sayfadasınız."))246 System.out.println("Geri buton calisiyor");247 } catch (Exception e) {248 System.err.println("Geri butonu bulunurken hata");249 }250 } catch (Exception e) {251 System.err.println("Cocuk ekranina gidilemedi");252 }253 }254 public static void main(String[] args) {255 AppiumAppTest a1 = new AppiumAppTest();256 try {257 a1.connectServer();258 a1.test1();259 a1.test2();...
sampleTestAOSapp_Android.java
Source:sampleTestAOSapp_Android.java
...37 @Test38 public void testAOSapp(){39 //Implicit wait40 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));41 driver.findElement(AppiumBy.xpath(42 "//android.view.ViewGroup[@content-desc=\"Home Page\"]/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.TextView"))43 .click();44 driver.findElement(AppiumBy.xpath(45 "//android.widget.RelativeLayout[@content-desc=\"Laptops\"]/android.widget.LinearLayout/android.widget.GridView/android.widget.RelativeLayout[4]/android.widget.TextView[1]"))46 .click();47 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/linearLayoutProductDetails")).click();48 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/imageViewProductDetailsClose")).click();49 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/linearLayoutProductQuantity")).click();50 driver.findElement(AppiumBy.xpath(51 "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.ImageView[2]"))52 .click();53 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/textViewApply")).click();54 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/buttonProductAddToCart")).click();55 driver.findElement(AppiumBy.xpath(56 "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.RelativeLayout[3]/android.widget.EditText"))57 .sendKeys("Username");58 driver.findElement(AppiumBy.xpath(59 "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.RelativeLayout[4]/android.widget.EditText"))60 .sendKeys("password");61 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/buttonLogin")).click();62 String ErrorMessage = driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/textViewFailed")).getText();63 assert ErrorMessage.contains("Incorrect user");64 driver.navigate().back();65 driver.navigate().back();66 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/imageViewMenu")).click();67 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/textViewMenuHome")).click();6869 }7071}7273
...
IOSTouchTest.java
Source:IOSTouchTest.java
...19@FixMethodOrder(MethodSorters.NAME_ASCENDING)20public class IOSTouchTest extends AppIOSTest {21 @Test22 public void tapTest() {23 WebElement intA = driver.findElement(By.id("IntegerA"));24 WebElement intB = driver.findElement(By.id("IntegerB"));25 intA.clear();26 intB.clear();27 intA.sendKeys("2");28 intB.sendKeys("4");29 WebElement e = driver.findElement(AppiumBy.accessibilityId("ComputeSumButton"));30 new IOSTouchAction(driver).tap(tapOptions().withElement(element(e))).perform();31 assertEquals(driver.findElement(By.xpath("//*[@name = \"Answer\"]")).getText(), "6");32 }33 @Test34 public void touchWithPressureTest() {35 WebElement intA = driver.findElement(By.id("IntegerA"));36 WebElement intB = driver.findElement(By.id("IntegerB"));37 intA.clear();38 intB.clear();39 intA.sendKeys("2");40 intB.sendKeys("4");41 WebElement e = driver.findElement(AppiumBy.accessibilityId("ComputeSumButton"));42 new IOSTouchAction(driver)43 .press(iosPressOptions()44 .withElement(element(e))45 .withPressure(1))46 .waitAction(waitOptions(ofMillis(100)))47 .release()48 .perform();49 assertEquals(driver.findElement(By.xpath("//*[@name = \"Answer\"]")).getText(), "6");50 }51 @Test public void multiTouchTest() {52 WebElement e = driver.findElement(AppiumBy.accessibilityId("ComputeSumButton"));53 WebElement e2 = driver.findElement(AppiumBy.accessibilityId("show alert"));54 IOSTouchAction tap1 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e)));55 IOSTouchAction tap2 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e2)));56 new MultiTouchAction(driver).add(tap1).add(tap2).perform();57 WebDriverWait waiting = new WebDriverWait(driver, Duration.ofSeconds(10));58 assertNotNull(waiting.until(alertIsPresent()));59 driver.switchTo().alert().accept();60 }61 @Test public void doubleTapTest() {62 WebElement firstField = driver.findElement(By.id("IntegerA"));63 firstField.sendKeys("2");64 IOSTouchAction iosTouchAction = new IOSTouchAction(driver);65 iosTouchAction.doubleTap(element(firstField));66 WebElement editingMenu = driver.findElement(AppiumBy.className("XCUIElementTypeTextField"));67 assertNotNull(editingMenu);68 }69}...
SwagLabsLoginIos.java
Source:SwagLabsLoginIos.java
...22 capabilities.setCapability("bundleId", "com.saucelabs.SwagLabsMobileApp");23 capabilities.setCapability("app", "/Users/gowthamipv/IdeaProjects/LoginPageios/src/test/resources/app/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.7.1.app");24 IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);25 Thread.sleep(3000);26 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Username\"]")).sendKeys("standard_user");27 Thread.sleep(3000);28 driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@name=\"test-Password\"]")).sendKeys("secret_sauce");29 Thread.sleep(3000);30 driver.findElement(By.xpath("//XCUIElementTypeOther[@name=\"test-LOGIN\"]")).click();31 Thread.sleep(3000);32 driver.findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[2]")).click();33 Thread.sleep(3000);34 driver.findElement(By.xpath("(//XCUIElementTypeOther[@name=\"1\"])[4]")).click();35 Thread.sleep(3000);36 TouchAction t = new TouchAction(driver);37 t.tap(PointOption.point(186,657)).perform();38 Thread.sleep(3000);39 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-First Name\"]")).sendKeys("Gowthami");40 Thread.sleep(3000);41 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Last Name\"]")).sendKeys("PV");42 Thread.sleep(3000);43 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Zip/Postal Code\"]")).sendKeys("563122");44 Thread.sleep(3000);45 driver.findElement(By.xpath("//XCUIElementTypeOther[@name=\"test-CONTINUE\"]")).click();46 Thread.sleep(3000);47 t.press(PointOption.point(206,762)).waitAction(WaitOptions.waitOptions(Duration.ofMillis((3000)))).moveTo(PointOption.point(215,204)).release().perform();48 Thread.sleep(3000);49 driver.findElement(new AppiumBy.ByAccessibilityId("test-FINISH")).click();50 Thread.sleep(3000);51 driver.findElement(new AppiumBy.ByAccessibilityId("test-BACK HOME")).click();52 Thread.sleep(3000);53 driver.quit();54 }55}...
WebViewTest.java
Source:WebViewTest.java
...32 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));33 }34 @Test35 void webview() throws InterruptedException {36 driver.findElement(By.cssSelector("*[description=Views]")).click();37 driver.findElement(AppiumBy.androidUIAutomator(38 "new UiScrollable(new UiSelector().scrollable(true))" +39 ".scrollIntoView(new UiSelector().text(\"WebView\"))")).click();40 String webviewContext = "WEBVIEW_io.appium.android.apis";41 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));42 wait.until(webDriver -> {43 Set<String> contexts = driver.getContextHandles();44 System.out.println(contexts);45 return contexts.contains(webviewContext);46 });47 driver.context(webviewContext);48 System.out.println(driver.getPageSource());49 System.out.println(driver.getWindowHandles());50 driver.getWindowHandles().forEach(window -> {51 driver.switchTo().window(window);52 System.out.println(driver.getTitle());53 System.out.println(driver.getCurrentUrl());54 });55 driver.findElement(By.name("i_am_a_textbox")).sendKeys("ceshiren.com");56 driver.findElement(By.linkText("i am a link")).click();57 assertThat(58 driver.findElement(By.cssSelector("body")).getText(),59 containsString("I am some other page content")60 );61 }62}...
AndroidAbilityToUseSupplierTest.java
Source:AndroidAbilityToUseSupplierTest.java
...13import org.openqa.selenium.WebElement;14import java.util.List;15public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {16 private final ActionSupplier<AndroidTouchAction> horizontalSwipe = () -> {17 driver.findElement(By.id("io.appium.android.apis:id/gallery"));18 WebElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery"));19 List<WebElement> images = gallery.findElements(AppiumBy.className("android.widget.ImageView"));20 Point location = gallery.getLocation();21 Point center = getCenter(gallery, location);22 ElementOption pressOption = element(images.get(2),-10,center.y - location.y);23 ElementOption moveOption = element(gallery, 10,center.y - location.y);24 return new AndroidTouchAction(driver)25 .press(pressOption)26 .waitAction(waitOptions(ofSeconds(2)))27 .moveTo(moveOption)28 .release();29 };30 private final ActionSupplier<AndroidTouchAction> verticalSwiping = () ->31 new AndroidTouchAction(driver)32 .press(element(driver.findElement(AppiumBy.accessibilityId("Gallery"))))33 .waitAction(waitOptions(ofSeconds(2)))34 .moveTo(element(driver.findElement(AppiumBy.accessibilityId("Auto Complete"))))35 .release();36 @Test public void horizontalSwipingWithSupplier() {37 Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1");38 driver.startActivity(activity);39 WebElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery"));40 List<WebElement> images = gallery.findElements(AppiumBy.className("android.widget.ImageView"));41 int originalImageCount = images.size();42 horizontalSwipe.get().perform();43 assertNotEquals(originalImageCount,44 gallery.findElements(AppiumBy.className("android.widget.ImageView")).size());45 }46 @Test public void verticalSwipingWithSupplier() throws Exception {47 driver.resetApp();48 driver.findElement(AppiumBy.accessibilityId("Views")).click();49 Point originalLocation = driver.findElement(AppiumBy.accessibilityId("Gallery")).getLocation();50 verticalSwiping.get().perform();51 Thread.sleep(5000);52 assertNotEquals(originalLocation, driver.findElement(AppiumBy.accessibilityId("Gallery")).getLocation());53 }54}...
sampleTestAOSapp_iOS.java
Source:sampleTestAOSapp_iOS.java
...3435 @Test36 public void testAOSapp(){37 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));38 driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name=\"LAPTOPS\"]")).click();39 driver.findElement(AppiumBy.accessibilityId("HP ENVY x360 - 15t Laptop")).click();40 wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("productDetailsButton"))).click();41 driver.findElement(AppiumBy.accessibilityId("Close2")).click();42 driver.findElement(AppiumBy.accessibilityId("quantityButtonId")).click();43 driver.findElement(AppiumBy.accessibilityId("Plus")).click();44 driver.findElement(AppiumBy.accessibilityId("APPLY")).click();45 driver.findElement(AppiumBy.accessibilityId("ADD TO CART")).click();46 driver.findElement(AppiumBy.accessibilityId("Ok")).click();47 driver.findElement(AppiumBy.accessibilityId("userNameLabel")).sendKeys("Username");48 driver.findElement(AppiumBy.accessibilityId("passwordLabel")).sendKeys("password");49 driver.findElement(AppiumBy.accessibilityId("LOGIN")).click();50 WebElement loginErrorText = wait.until(ExpectedConditions.presenceOfElementLocated(51 AppiumBy.accessibilityId("Incorrect user name or password.")));52 assert loginErrorText.isDisplayed() == true;53 wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("Menu"))).click();54 driver.findElement(AppiumBy.accessibilityId("HOME")).click();55 }56}
...
LoginTests.java
Source:LoginTests.java
...8public class LoginTests extends TestBase {9 @Test(dataProvider = "EmulatorSimulatorDataProvider")10 public void invalidCredentials(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {11 createDriver(platform, deviceName, platformVersion, methodName.getName());12 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("bad");13 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("bad");14 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();15 Assert.assertTrue(getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Error message")).isDisplayed());16 }17 @Test(dataProvider = "EmulatorSimulatorDataProvider")18 public void blankCredentials(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {19 createDriver(platform, deviceName, platformVersion, methodName.getName());20 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("");21 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("");22 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();23 Assert.assertTrue(getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Error message")).isDisplayed());24 }25 @Test(dataProvider = "EmulatorSimulatorDataProvider")26 public void validCredentials(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {27 createDriver(platform, deviceName, platformVersion, methodName.getName());28 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("standard_user");29 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("secret_sauce");30 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();31 if (platform.equalsIgnoreCase("Android")) {32 Assert.assertTrue(getDriver().findElement(By.xpath("(//android.view.ViewGroup[@content-desc=\"test-ADD TO CART\"])[1]")).isDisplayed());33 } else {34 Assert.assertTrue(getDriver().findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[1]")).isDisplayed());35 }36 }37}...
findElement
Using AI Code Generation
1WebElement element = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));2List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));3WebElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements().withName(\"Accessibility\")"));4List<WebElement> elements = driver.findElements(AppiumBy.IosUIAutomation(".elements().withName(\"Accessibility\")"));5WebElement element = driver.findElement(AppiumBy.AndroidUIAutomator("new UiSelector().description(\"Accessibility\")"));6List<WebElement> elements = driver.findElements(AppiumBy.AndroidUIAutomator("new UiSelector().description(\"Accessibility\")"));7WebElement element = driver.findElement(AppiumBy.Image("image.jpg"));8List<WebElement> elements = driver.findElements(AppiumBy.Image("image.jpg"));9WebElement element = driver.findElement(AppiumBy.AndroidViewTag("android.view.View"));10List<WebElement> elements = driver.findElements(AppiumBy.AndroidViewTag("android.view.View"));11WebElement element = driver.findElement(AppiumBy.IosClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]"));12List<WebElement> elements = driver.findElements(AppiumBy.IosClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther
findElement
Using AI Code Generation
1package appium;2import java.net.URL;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.AppiumDriver;8import io.appium.java_client.MobileElement;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.remote.MobileCapabilityType;11public class Appium {12 public static void main(String[] args) throws Exception {13 DesiredCapabilities caps = new DesiredCapabilities();14 caps.setCapability("deviceName", "Pixel 3 API 29");15 caps.setCapability("platformName", "Android");16 caps.setCapability("appPackage", "com.androidsample.generalstore");17 caps.setCapability("appActivity", ".SplashActivity");18 caps.setCapability("noReset", "true");
findElement
Using AI Code Generation
1WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));2List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));3WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));4List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));5WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));6List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));7WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));8List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));9WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));10List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));11WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));12List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));13WebElement element = driver.findElement(AppiumBy.AccessibilityId("Content"));14List<WebElement> elements = driver.findElements(AppiumBy.AccessibilityId("Content"));
findElement
Using AI Code Generation
1WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));2List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));3WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));4List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));5WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));6List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));7WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));8List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));9WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));10List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));11WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));12List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));13WebElement el = driver.findElement(AppiumBy.AccessibilityId("Accessibility"));14List<WebElement> els = driver.findElements(AppiumBy.AccessibilityId("Accessibility"));
findElement
Using AI Code Generation
1WebElement searchBox = driver.findElement(AppiumBy.id("com.android.calculator2:id/digit_2"));2WebElement searchBox = driver.findElement(AppiumBy.name("Name"));3WebElement searchBox = driver.findElement(AppiumBy.className("android.widget.Button"));4WebElement searchBox = driver.findElement(AppiumBy.AccessibilityId("clear"));5WebElement searchBox = driver.findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeTextField[`label == 'IntegerA'`]"));6WebElement searchBox = driver.findElement(AppiumBy.iOSNsPredicateString("label == 'IntegerA'"));7WebElement searchBox = driver.findElement(AppiumBy.iOSUIAutomation(".elements()[0]"));8WebElement searchBox = driver.findElement(AppiumBy.AndroidUIAutomator("new UiSelector().description(\"clear\")"));9WebElement searchBox = driver.findElement(AppiumBy.AndroidViewTag("clear"));10WebElement searchBox = driver.findElement(AppiumBy.AndroidDataMatcher("withContentDescription", "clear"));
findElement
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.AppiumDriver;6import io.appium.java_client.MobileElement;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.remote.MobileCapabilityType;9public class FindElementByAndroidUIAutomator {10 public static void main(String[] args) throws MalformedURLException, InterruptedException {11 DesiredCapabilities cap = new DesiredCapabilities();12 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");13 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");14 cap.setCapability(MobileCapabilityType.UDID, "emulator-5554");15 cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 14);16 cap.setCapability("appPackage", "com.androidsample.generalstore");17 cap.setCapability("appActivity", ".SplashActivity");
findElement
Using AI Code Generation
1element.click();2element.click();3element.click();4element.click();5element.click();6element.click();7element.click();
findElement
Using AI Code Generation
1public class AppiumByTest {2 public static void main(String[] args) throws MalformedURLException {3 DesiredCapabilities capabilities = new DesiredCapabilities();4 capabilities.setCapability(CapabilityType.BROWSER_NAME, "");5 capabilities.setCapability("deviceName", "Android Emulator");6 capabilities.setCapability("platformVersion", "4.4");7 capabilities.setCapability("platformName", "Android");8 capabilities.setCapability("appPackage", "com.android.calculator2");9 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!