question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: iOSXCUITestFindBy is not working properly for xpath or iosClassChain

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I am trying to find the Search Box in the iOS Settings app. This is my locator: @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeSearchField[$name ==[C] 'Search'$]") private WebElement weSearchText;

The same is working fine with AppiumBy variable.

This is my appium instantiation from log: image

When I execute that line, I got this in log: image

As you can see, it seems that the logs are sending my element name as iosClassChain instead of my locator: {"using":"class chain","value":"**/*[name == "weSearchTextBox"]"}

What am I doing wrong here?

I tried @FindBy similarly for Xpath and that worked fine.

Expected Behavior

The element should ideally get identified properly.

Minimal Reproducible Example

package com.tekioncloud.core.main.mobile.pages;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;

import java.net.MalformedURLException;
import java.net.URL;

public class MobileSettingsAppTest {

    @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`label ==[C] 'General'`]")
    private WebElement weGeneral;

    private By byGeneral = AppiumBy.iOSClassChain("**/XCUIElementTypeCell[`label ==[C] 'General'`]");

    public static void main(String[] args) {
        try {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.setCapability("platformName", "iOS");
            desiredCapabilities.setCapability("appium:automationName", "XCUITest");
            desiredCapabilities.setCapability("appium:bundleId", "com.apple.Preferences");
            desiredCapabilities.setCapability("appium:deviceName", "iPhone XR");
            desiredCapabilities.setCapability("appium:newCommandTimeout", "0");
            desiredCapabilities.setCapability("appium:platformVersion", "12.1");
            desiredCapabilities.setCapability("appium:udid", "00008020-001B044C0193802E");
            desiredCapabilities.setCapability("appium:waitForQuiescence", false);
            desiredCapabilities.setCapability("appium:wdaLocalPort", "8100");

            IOSDriver iDriver = new IOSDriver(new URL("http://0.0.0.0:4723"), desiredCapabilities);
            iDriver.setSetting("useFirstMatch", true);

            MobileSettingsAppTest mobileSettingsAppTest = new MobileSettingsAppTest();
            PageFactory.initElements(iDriver,mobileSettingsAppTest);
            mobileSettingsAppTest.weGeneral.click();
//            iDriver.findElement(mobileSettingsAppTest.byGeneral).click();
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
}

Environment

  • Operating system:
  • If running via appium CLI…
    • Appium CLI version (output of appium --version): 2.0.0-beta.44
    • Node.js version (output of node --version): v18.7.0
    • npm version (output of npm --version): 8.18.0
    • Last appium version which did not exhibit the problem: Didn’t try this previously
  • If running Appium Desktop, its version: NA
  • Appium driver(s) and their version(s): xcuitest@4.11.1
  • Appium plugin(s) and their version(s): NA
  • Platform and version under test: iOS 16.1.1
  • Real device or emulator/simulator: iPhone XR real device

Link to Appium Logs

No response

Futher Information

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mykola-mokhnachcommented, Nov 14, 2022

It looks like java client lib unexpectedly changes the locator to CSS type? Are you sure the most recent version of it is used?

0reactions
aarahmanqacommented, Nov 14, 2022

Yeah, its working now. Thanks @mykola-mokhnach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - @iOSXCUITFindBy Annotations don't work but the same ...
When I am using below its working fine, but when I am using pagefactory annotations. driver.findElement(By.xpath("//*[@class='UIAButton'][2]")).
Read more >
@iOSXCUITFindBy Annotations don't work but the same code ...
@iOSXCUITFindBy Annotations don't work but the same code works when I use driver.findElement(By.accessibilityid) or even xpath · Issues/Bugs.
Read more >
appium/appium - Gitter
Hi all, I see @iosxcuitfindby annotation not working for my scripts..I used all attributes like xpath, class chain, accessibility ld. But If I ......
Read more >
Integrate PageFactory with PageObjectModel in appium
... with PageObjectModel in appium | @AndroidFindBy | @ iOSXCUITFindBy ... An error occurred while retrieving sharing information.
Read more >
Even after providing proper xpath for element on mobile ...
following is the errror i get " Error msg is: An element could not be located on the page using ... 'XPATH' with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found