How to use findElements method of io.appium.java_client.AppiumBy class

Best io.appium code snippet using io.appium.java_client.AppiumBy.findElements

NotePadTest.java

Source:NotePadTest.java Github

copy

Full Screen

...19 wait.until(ExpectedConditions.visibilityOfElementLocated(20 AppiumBy.accessibilityId("More options"))).click();21 wait.until(ExpectedConditions.visibilityOfElementLocated(22 AppiumBy.className("android.widget.ListView")));23 List<WebElement> listElements = driver.findElements(AppiumBy.id("com.farmerbb.notepad:id/title"));24 assertEquals(listElements.size(), 3);25 assertEquals(listElements.get(0).getText(), "Settings");26 assertEquals(listElements.get(1).getText(), "Import notes");27 assertEquals(listElements.get(2).getText(), "About Notepad");28 }29 @Test30 //verify selecting checkbox in setting option31 public void verifySettings() {32 final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));33 Activity activity = new Activity("com.farmerbb.notepad", "com.farmerbb.notepad.MainActivity");34 driver.startActivity(activity);35 wait.until(ExpectedConditions.visibilityOfElementLocated(36 AppiumBy.accessibilityId("More options"))).click();37 wait.until(ExpectedConditions.visibilityOfElementLocated(38 AppiumBy.className("android.widget.ListView")));39 wait.until(ExpectedConditions.visibilityOfElementLocated(40 By.xpath(".//*[@text='Settings']"))).click();41 wait.until(ExpectedConditions.visibilityOfElementLocated(42 AppiumBy.className("android.widget.ListView")));43 List<WebElement> listElements = driver.findElements(AppiumBy.id("android:id/checkbox"));44 assertEquals(listElements.size(), 4);45 Iterator<WebElement> elementIterator = listElements.iterator();46 while(elementIterator.hasNext()) {47 WebElement element = elementIterator.next();48 if (element.getAttribute("enabled").equals("true")) {49 element.click();50 }51 }52 driver.navigate().back();53 wait.until(ExpectedConditions.visibilityOfElementLocated(54 AppiumBy.accessibilityId("More options"))).click();55 wait.until(ExpectedConditions.visibilityOfElementLocated(56 AppiumBy.className("android.widget.ListView")));57 wait.until(ExpectedConditions.visibilityOfElementLocated(58 By.xpath(".//*[@text='Settings']"))).click();59 wait.until(ExpectedConditions.visibilityOfElementLocated(60 AppiumBy.className("android.widget.ListView")));61 listElements = driver.findElements(AppiumBy.id("android:id/checkbox"));62 elementIterator = listElements.iterator();63 while(elementIterator.hasNext()) {64 WebElement element = elementIterator.next();65 if (element.getAttribute("enabled").equals("true")) {66 assertEquals(element.getAttribute("checked"), "true");67 }68 }69 }70 @Test71 //verify creating notes72 public void verifyCreateNotes() {73 final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));74 Activity activity = new Activity("com.farmerbb.notepad", "com.farmerbb.notepad.MainActivity");75 driver.startActivity(activity);...

Full Screen

Full Screen

AndroidElementTest.java

Source:AndroidElementTest.java Github

copy

Full Screen

...31 @Test public void findByAccessibilityIdTest() {32 assertNotEquals(driver.findElement(By.id("android:id/content"))33 .findElement(AppiumBy.accessibilityId("Graphics")).getText(), null);34 assertEquals(driver.findElement(By.id("android:id/content"))35 .findElements(AppiumBy.accessibilityId("Graphics")).size(), 1);36 }37 @Test public void findByAndroidUIAutomatorTest() {38 assertNotEquals(driver.findElement(By.id("android:id/content"))39 .findElement(AppiumBy40 .androidUIAutomator("new UiSelector().clickable(true)")).getText(), null);41 assertNotEquals(driver.findElement(By.id("android:id/content"))42 .findElements(AppiumBy43 .androidUIAutomator("new UiSelector().clickable(true)")).size(), 0);44 assertNotEquals(driver.findElement(By.id("android:id/content"))45 .findElements(AppiumBy46 .androidUIAutomator("new UiSelector().clickable(true)")).size(), 1);47 }48 @Test public void replaceValueTest() {49 String originalValue = "original value";50 Activity activity = new Activity("io.appium.android.apis", ".view.Controls1");51 driver.startActivity(activity);52 WebElement editElement = driver53 .findElement(AppiumBy.androidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));54 editElement.sendKeys(originalValue);55 assertEquals(originalValue, editElement.getText());56 String replacedValue = "replaced value";57 driver.replaceElementValue((RemoteWebElement) editElement, replacedValue);58 assertEquals(replacedValue, editElement.getText());59 }...

Full Screen

Full Screen

AndroidAbilityToUseSupplierTest.java

Source:AndroidAbilityToUseSupplierTest.java Github

copy

Full Screen

...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}...

Full Screen

Full Screen

ecommerce_tc_3.java

Source:ecommerce_tc_3.java Github

copy

Full Screen

...24 WebElement tap_brazil = driver.findElementByAndroidUIAutomator(25 "new UiScrollable(new UiSelector()).scrollIntoView(text(\"Brazil\"));");26 t.tap(tapOptions().withElement(element(tap_brazil))).perform();27 driver.findElement(By.id("com.androidsample.generalstore:id/btnLetsShop")).click();28 System.out.println(driver.findElements(By.id("com.androidsample.generalstore:id/productName")).size());29 // com.androidsample.generalstore:id/rvProductList30 // WebElement radioGroup = driver.findElement(AppiumBy.androidUIAutomator("new31 // UiScrollable(new32 // UiSelector().resourceId(\"android:id/list\")).scrollIntoView(new33 // UiSelector().text(\"Radio Group\"));"));34 // assertNotNull(radioGroup.getLocation());35 // SCROLL PADRÃO PARA ENCONTRAR O ELEMENTO36 driver.findElement(MobileBy.AndroidUIAutomator(37 "new UiScrollable(new UiSelector().resourceId(\"com.androidsample.generalstore:id/rvProductList\")).scrollIntoView(new UiSelector().textMatches(\"Nike SFB Jungle\").instance(0));"));38 int count = driver.findElements(By.id("com.androidsample.generalstore:id/productName")).size();39 for (int i = 0; i < count; i++) {40 String text = driver.findElements(By.id("com.androidsample.generalstore:id/productName")).get(i).getText();41 if (text.equalsIgnoreCase("Nike SFB Jungle")) {42 driver.findElements(By.id("com.androidsample.generalstore:id/productAddCart")).get(i).click();43 break;44 }45 }46 driver.findElement(By.id("com.androidsample.generalstore:id/appbar_btn_cart")).click();47 String textProductCar = driver.findElement(By.id("com.androidsample.generalstore:id/productName")).getText();48 System.out.println(textProductCar);49 Assert.assertEquals("Nike SFB Jungle", textProductCar);50 }51}...

Full Screen

Full Screen

AndroidSearchingTest.java

Source:AndroidSearchingTest.java Github

copy

Full Screen

...29 driver.startActivity(activity);30 }31 @Test public void findByAccessibilityIdTest() {32 assertNotEquals(driver.findElement(AppiumBy.accessibilityId("Graphics")).getText(), null);33 assertEquals(driver.findElements(AppiumBy.accessibilityId("Graphics")).size(), 1);34 }35 @Test public void findByAndroidUIAutomatorTest() {36 assertNotEquals(driver37 .findElement(AppiumBy38 .androidUIAutomator("new UiSelector().clickable(true)")).getText(), null);39 assertNotEquals(driver40 .findElements(AppiumBy41 .androidUIAutomator("new UiSelector().clickable(true)")).size(), 0);42 assertNotEquals(driver43 .findElements(AppiumBy44 .androidUIAutomator("new UiSelector().clickable(true)")).size(), 1);45 }46 @Test public void findByXPathTest() {47 By byXPath = By.xpath("//android.widget.TextView[contains(@text, 'Animat')]");48 assertNotNull(driver.findElement(byXPath).getText());49 assertEquals(driver.findElements(byXPath).size(), 1);50 }51 @Test public void findScrollable() {52 driver.findElement(AppiumBy.accessibilityId("Views")).click();53 WebElement radioGroup = driver54 .findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector()"55 + ".resourceId(\"android:id/list\")).scrollIntoView("56 + "new UiSelector().text(\"Radio Group\"));"));57 assertNotNull(radioGroup.getLocation());58 }59}...

Full Screen

Full Screen

ecommerce_tc_4.java

Source:ecommerce_tc_4.java Github

copy

Full Screen

...22 WebElement tap_brazil = driver.findElementByAndroidUIAutomator(23 "new UiScrollable(new UiSelector()).scrollIntoView(text(\"Brazil\"));");24 t.tap(tapOptions().withElement(element(tap_brazil))).perform();25 driver.findElement(By.id("com.androidsample.generalstore:id/btnLetsShop")).click();26 System.out.println(driver.findElements(By.id("com.androidsample.generalstore:id/productName")).size());27 // com.androidsample.generalstore:id/rvProductList28 // WebElement radioGroup = driver.findElement(AppiumBy.androidUIAutomator("new29 // UiScrollable(new30 // UiSelector().resourceId(\"android:id/list\")).scrollIntoView(new31 // UiSelector().text(\"Radio Group\"));"));32 // assertNotNull(radioGroup.getLocation());33 // SCROLL PADRÃO PARA ENCONTRAR O ELEMENTO34 driver.findElement(MobileBy.AndroidUIAutomator(35 "new UiScrollable(new UiSelector().resourceId(\"com.androidsample.generalstore:id/rvProductList\")).scrollIntoView(new UiSelector().textMatches(\"Nike SFB Jungle\").instance(0));"));36 int count = driver.findElements(By.id("com.androidsample.generalstore:id/productName")).size();37 for (int i = 0; i < count; i++) {38 String text = driver.findElements(By.id("com.androidsample.generalstore:id/productName")).get(i).getText();39 if (text.equalsIgnoreCase("Nike SFB Jungle")) {40 driver.findElements(By.id("com.androidsample.generalstore:id/productAddCart")).get(i).click();41 break;42 }43 }44 driver.findElement(By.id("com.androidsample.generalstore:id/appbar_btn_cart")).click();45 }46}...

Full Screen

Full Screen

SettingsPage.java

Source:SettingsPage.java Github

copy

Full Screen

...18 wait = new WebDriverWait(driver, Duration.ofSeconds(30));19 }20 public void selectAllCheckBoxes() {21 wait.until(ExpectedConditions.visibilityOfElementLocated(listView));22 List<WebElement> listElements = driver.findElements(checkBox);23 Iterator<WebElement> elementIterator = listElements.iterator();24 while(elementIterator.hasNext()) {25 WebElement element = elementIterator.next();26 if (element.getAttribute("enabled").equals("true") &&27 element.getAttribute("checked").equals("false")) {28 element.click();29 }30 }31 }32 public int getCheckBoxesCount() {33 wait.until(ExpectedConditions.visibilityOfElementLocated(listView));34 List<WebElement> listElements = driver.findElements(checkBox);35 return listElements.size();36 }37 public void verifyAllCheckBoxesAreSelected() {38 wait.until(ExpectedConditions.visibilityOfElementLocated(listView));39 List<WebElement> listElements = driver.findElements(checkBox);40 Iterator<WebElement> elementIterator = listElements.iterator();41 while(elementIterator.hasNext()) {42 WebElement element = elementIterator.next();43 if (element.getAttribute("enabled").equals("true")) {44 assertEquals(element.getAttribute("checked"), "true");45 }46 }47 }48}...

Full Screen

Full Screen

IOSSearchingTest.java

Source:IOSSearchingTest.java Github

copy

Full Screen

...22 assertNotEquals(driver23 .findElement(AppiumBy.accessibilityId("ComputeSumButton"))24 .getText(), null);25 assertNotEquals(driver26 .findElements(AppiumBy.accessibilityId("ComputeSumButton"))27 .size(), 0);28 }29 @Test public void findByByIosPredicatesTest() {30 assertNotEquals(driver31 .findElement(AppiumBy.iOSNsPredicateString("name like 'Answer'"))32 .getText(), null);33 assertNotEquals(driver34 .findElements(AppiumBy.iOSNsPredicateString("name like 'Answer'"))35 .size(), 0);36 }37 @Test public void findByByIosClassChainTest() {38 assertNotEquals(driver39 .findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeButton"))40 .getText(), null);41 assertNotEquals(driver42 .findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeButton"))43 .size(), 0);44 }45}...

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidKeyCode;5import io.appium.java_client.android.AndroidElement;6import io.appium.java_client.AppiumBy;7import io.appium.java_client.MobileBy;8import io.appium.java_client.android.AndroidKeyCode;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.android.AndroidElement;11import io.appium.java_client.AppiumDriver;12import io.appium.java_client.MobileElement;13import io.appium.java_client.AppiumBy;14import io.appium.java_client.MobileBy;15import io.appium.java_client.android.AndroidKeyCode;16import io.appium.java_client.android.AndroidDriver;17import io.appium.java_client.android.AndroidElement;18import io.appium.java_client.AppiumDriver;19import io.appium.java_client.MobileElement;20import io.appium.java_client.AppiumBy;21import io.appium.java_client.MobileBy;22import io.appium.java_client.android.AndroidKeyCode;23import io.appium.java_client.android.AndroidDriver;24import io.appium.java_client.android.AndroidElement;25import io.appium.java_client.AppiumDriver;26import io.appium.java_client.MobileElement;27import io.appium.java_client.AppiumBy;28import io.appium.java_client.MobileBy;29import io.appium.java_client.android.AndroidKeyCode;30import io.appium.java_client.android.AndroidDriver;31import io.appium.java_client.android.AndroidElement;32import io.appium.java_client.AppiumDriver;33import io.appium.java_client.MobileElement;34import io.appium.java_client.AppiumBy;35import io.appium.java_client.MobileBy;36import io.appium.java_client.android.AndroidKeyCode;37import io.appium.java_client.android.AndroidDriver;38import io.appium.java_client.android.AndroidElement;39import io.appium.java_client.AppiumDriver;40import io.appium.java_client.MobileElement;41import io.appium.java_client.AppiumBy;42import io.appium.java_client.MobileBy;43import io.appium.java_client.android.AndroidKeyCode;44import io.appium.java_client.android.AndroidDriver;45import io.appium.java_client.android.AndroidElement;46import io.appium.java_client.AppiumDriver;47import io.appium.java_client.MobileElement;48import io.appium.java_client.AppiumBy;49import io.appium.java_client.MobileBy;50import io.appium.java_client.android.AndroidKeyCode;51import io.appium.java_client.android.AndroidDriver;52import io

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1package appium.java;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.MobileElement;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.android.AndroidElement;6import io.appium.java_client.remote.MobileCapabilityType;7import org.openqa.selenium.By;8import org.openqa.selenium.remote.DesiredCapabilities;9import java.net.MalformedURLException;10import java.net.URL;11import java.util.List;12public class AppiumJava {13 public static void main(String[] args) throws MalformedURLException {14 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();15 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");16 desiredCapabilities.setCapability(MobileCapabilityType.APP, "C:\\Users\\sharath\\Downloads\\ApiDemos-debug.apk");17 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");18 driver.findElementByAndroidUIAutomator("text(\"Views\")").click();19 driver.findElementByAndroidUIAutomator("text(\"Expandable Lists\")").click();20 driver.findElementByAndroidUIAutomator("text(\"1. Custom Adapter\")").click();21 List<AndroidElement> elements = driver.findElementsByAndroidUIAutomator("new UiSelector().clickable(true)");22 System.out.println(elements.size());23 for (AndroidElement element : elements) {24 System.out.println(element.getText());25 }26 }27}

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidElement;5import io.appium.java_client.android.AndroidKeyCode;6import io.appium.java_client.android.AndroidKeyMetastate;7import io.appium.java_client.android.AndroidKeyMetastate.Builder;8import io.appium.java_client.android.AndroidTouchAction;9import io.appium.java_client.remote.MobileCapabilityType;10import io.appium.java_client.touch.WaitOptions;11import io.appium.java_client.touch.offset.PointOption;12import java.net.MalformedURLException;13import java.net.URL;14import java.time.Duration;15import java.util.List;16import org.openqa.selenium.By;17import org.openqa.selenium.Dimension;18import org.openqa.selenium.remote.DesiredCapabilities;19import org.testng.Assert;20import org.testng.annotations.AfterTest;21import org.testng.annotations.BeforeTest;22import org.testng.annotations.Test;23public class FindElementsByXpath {24 AppiumDriver<MobileElement> driver = null;25 public void setUp() throws MalformedURLException {26 DesiredCapabilities caps = new DesiredCapabilities();27 caps.setCapability("deviceName", "Pixel 2 API 28");28 caps.setCapability("platformName", "Android");29 caps.setCapability("appPackage", "com.android.contacts");30 caps.setCapability("appActivity", "com.android.contacts.activities.PeopleActivity");31 caps.setCapability("noReset", true);

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1List<MobileElement> elements = driver.findElements(AppiumBy.IosUIAutomation(".elements()"));2System.out.println("Total elements found " + elements.size());3MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[0]"));4System.out.println("First element found " + element.getText());5MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[1]"));6System.out.println("Second element found " + element.getText());7MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[2]"));8System.out.println("Third element found " + element.getText());9MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[3]"));10System.out.println("Fourth element found " + element.getText());11MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[4]"));12System.out.println("Fifth element found " + element.getText());13MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[5]"));14System.out.println("Sixth element found " + element.getText());15MobileElement element = driver.findElement(AppiumBy.IosUIAutomation(".elements()[6]"));16System.out.println("Seventh element found " + element.getText());

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.List;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.remote.DesiredCapabilities;9import io.appium.java_client.AppiumDriver;10import io.appium.java_client.MobileElement;11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.remote.MobileCapabilityType;13public class Appium {14 public static void main(String[] args) throws MalformedURLException {15 DesiredCapabilities caps = new DesiredCapabilities();16 caps.setCapability("deviceName", "Pixel 3 API 28");17 caps.setCapability("platformName", "Android");18 caps.setCapability("platformVersion", "9.0");19 caps.setCapability("appPackage", "com.android.calculator2");20 caps.setCapability("appActivity", "com.android.calculator2.Calculator");21 caps.setCapability("noReset", "true");

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1List<MobileElement> elements = driver.findElements(AppiumBy.AndroidUIAutomator("new UiSelector().text(\"Add\")"));2System.out.println("The number of elements with text property as Add are: " + elements.size());3List<MobileElement> elements = driver.findElements(AppiumBy.AndroidUIAutomator("new UiSelector().description(\"Add\")"));4System.out.println("The number of elements with description property as Add are: " + elements.size());5List<MobileElement> elements = driver.findElements(AppiumBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.android.calculator2:id/digit_5\")"));6System.out.println("The number of elements with resource-id property as com.android.calculator2:id/digit_5 are: " + elements.size());7List<MobileElement> elements = driver.findElements(AppiumBy.AndroidUIAutomator("new UiSelector().className(\"android.widget.Button\")"));8System.out.println("The number of elements with class name as android.widget.Button are: " + elements.size());9List<MobileElement> elements = driver.findElements(AppiumBy.AndroidUIAutomator("new UiSelector().checkable(\"true\")"));10System.out.println("The number of elements with checkable property as true are: " + elements.size());

Full Screen

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 io.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