@AndroidFindBy unsupported CSS Selector

Hi,

I am starting a new project and creating the pageObjects using the PageFactory approach. I am facing an error that I’m not able to resolve so far, any help would be appreciated please.

The code snippet:

package pageObjects;

import static org.junit.Assert.assertTrue;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;

import io.appium.java_client.pagefactory.AndroidBy;
import io.appium.java_client.pagefactory.AndroidFindBy;
import util.hook;

public class onBoardingPage {

public onBoardingPage() {
PageFactory.initElements(hook.getDriver(), this);
}
@AndroidFindBy(id = “button_proceed”)
public WebElement proceedBtn;
}

Whenever I call this button “proceedBtn”, I receive this error:

Unsupported CSS selector ‘*[name=‘proceedBtn’]’. Reason: ‘Error: ‘name’ is not a valid attribute. Supported attributes are ‘checkable, checked, clickable, enabled, focusable, focused, long-clickable, scrollable, selected, index, instance, description, resource-id, text, class-name, package-name’’

I am calling it in another class through:
assertTrue(proceedBtn.isDisplayed());

Much appreciated,
Tarek

What are capabilities? Can you post full log as Git Gist?

https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists

@wreed I am so sorry for the late reply. Here is the gist of the error log I receive when I run the automation: https://gist.github.com/Tarek-O/23690585c3e9e3b3c9adc801e48cbca3
The capabilities are here: https://gist.github.com/Tarek-O/51bcfe66655aa9366637bf45d9a6e498

The normal driver.findElement(By.xpath()); and such are working as expected. However, the @AndroidFindBy tags are not working at all.

I might have missed a dependency, so here is the pom I’m currently using : https://gist.github.com/Tarek-O/329464eddc55a34324ac3be417ba46a2

Thank you,
Tarek

instead of this:
PageFactory.initElements(hook.getDriver(), this);
write as follow:
PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver()), this);
or, if you want to specify a maximum timeout when locating the element:
PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver(), timeout), this);
when the timeout variable is an int (like 15) or a Duration instance (like Duration.ofSeconds(15)) - depends on your client and its version.

the problem is that it is decorating the page object instance (“this”) with selenium’s decorator (the default) - you need to pass it appium’s decorator named: AppiumFieldDecorator and then it will know to look for @AndroidFindBy annotation and other mobile annotations.
like you can understand by the error, the PageFactory(the element’s proxy) tried to locate the element with the variable’s name (proceedBtn) which is the default behaviour and did not use the locator (button_proceed) at all. again, because it did not realize the annotation.

Thank you @ido_oserovitz for the fast and nice reply. I appreciate the explanation. I have implemented what you suggested, and now I’m facing another issue/error. The error log: gist:60481c6ef95fd5803d49ee5bb221a6f9 · GitHub
The statements where the error log is pointing at are where I call the PageObjects class in my Stepdefinition class:
public explorePage explorePage = new explorePage();
And the constructor of the PageObject:

public explorePage() {
PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver()), this);
}

Edit: I believe this issue might be caused by Eclipse’s execution java version. I am trying to resolve it and will update the thread.

please provide more code and info, it is not enough. do not post only what you think is wrong, send more so we can really help.
for now, you get java.lang.NoSuchMethodException: jdk.proxy2.$Proxy17.proxyClassLookup()
and it looks like you call a method that does not exist. the constructor looks good and from the stack trace in the link you sent I can see that the constructor got invoked so maybe it is a different method call you do afterward in the test class.

some important things. the standard writing is to start class’ names with uppercase and variable’s names with lowercase.
this: public explorePage explorePage = new explorePage();
should be: public ExplorePage explorePage = new ExplorePage(); and the constructor should be with uppercase as well.

@ido_oserovitz , thank you for the suggestion. I will work on it.
The error stack when running the code now: https://gist.github.com/Tarek-O/23948298cc752fd7ba5c28049ae9c38b
The three classes being used: https://gist.github.com/Tarek-O/81552f455712c9e2ecc58e37aab7ad81

I hope this is enough code and logs. Please let me know if there’s any more info I can give to help.

Thank you so much,
Tarek

Issue resolved after upgrading the Local Java and IDE java and compiler version from Java 8 to Java 11. Thread can be closed now, thank you all for the help.

1 Like