appium / dotnet-client

Extension to the official Selenium dotnet webdriver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All Android Tests I now get a CSS Selector exception for

aaronportier opened this issue · comments

Description

I login to the application
Then any Calls I make XPath or id or automation id results in a CSS Selector issue.
The only changes I made was I upgraded and fixed all the breaking changes to see that it can't call any elements.
OpenQA.Selenium.InvalidSelectorException : Locator Strategy 'css selector' is not supported for this session; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalid-selector-exception

iOS works better as it passes in the Cloud Provider but Visual Studio fails with this OpenQA.Selenium.WebDriverException : The executeScript command returned an unexpected error.

@aaronportier, please provide full code sample and appium versions in use.
Otherwise it will be hard to assist you

@aaronportier, what do you mean by search by css selector?
The semi code you sent suggest you use search by ID.
So which one is it?
MobileBy.Id(com.rd.appname:id/FilterIconbutton
But again, it will be helpful if you coyote share a full scenario of the flow

You get css selector in the error because of the selenium generic exception for elements locators.
Anyway I suggest you use Appium inspector in order to find the proper ID of the element.

The element exists its the ID. I used Appium Inspector and it exists just fine. Once I upgraded Id's do not seem to work.

2023-11-21 20:08:28:217 - [HTTP] --> POST /wd/hub/session/24f24ea5-7578-4152-8f4e-4b5e64ece043/element
2023-11-21 20:08:28:217 - [HTTP] {"using":"css selector","value":"#com\.rd\.appname\:id\/FilterIconbutton"}
2023-11-21 20:08:28:218 - [debug] [W3C (24f24ea5)] Calling AppiumDriver.findElement() with args: ["css selector","#com\.rd\.appname\:id\/FilterIconbutton","24f24ea5-7578-4152-8f4e-4b5e64ece043"]
2023-11-21 20:08:28:218 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2023-11-21 20:08:28:220 - [debug] [W3C (24f24ea5)] Encountered internal error running command: InvalidSelectorError: Locator Strategy 'css selector' is not supported for this session
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at AndroidUiautomator2Driver.validateLocatorStrategy (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/appium-base-driver/lib/basedriver/driver.js:388:13)
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/appium-base-driver/lib/basedriver/commands/find.js:31:8)
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at AndroidUiautomator2Driver.findElement (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/appium-base-driver/lib/basedriver/commands/find.js:53:21)
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at commandExecutor (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/appium-base-driver/lib/basedriver/driver.js:330:9)
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at /nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/async-lock/lib/index.js:125:12
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at AsyncLock._promiseTry (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/async-lock/lib/index.js:249:31)
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at exec (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/async-lock/lib/index.js:124:9)
2023-11-21 20:08:28:221 - [debug] [W3C (24f24ea5)] at AsyncLock.acquire (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/async-lock/lib/index.js:140:3)
2023-11-21 20:08:28:222 - [debug] [W3C (24f24ea5)] at AndroidUiautomator2Driver.executeCommand (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/appium-base-driver/lib/basedriver/driver.js:343:39)
2023-11-21 20:08:28:222 - [debug] [W3C (24f24ea5)] at AppiumDriver.executeCommand (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/lib/appium.js:534:36)
2023-11-21 20:08:28:222 - [debug] [W3C (24f24ea5)] at runMicrotasks ()
2023-11-21 20:08:28:222 - [debug] [W3C (24f24ea5)] at processTicksAndRejections (internal/process/task_queues.js:97:5)
2023-11-21 20:08:28:222 - [debug] [W3C (24f24ea5)] at asyncHandler (/nix/store/a4f03fnyb1njsg95d11hrirds8hfjsc1-appium-1.17.0/node_modules/appium-base-driver/lib/protocol/protocol.js:309:21)
2023-11-21 20:08:28:223 - [HTTP] <-- POST /wd/hub/session/24f24ea5-7578-4152-8f4e-4b5e64ece043/element 400 5 ms - 2306

So I think I know where the issue is, if you say it worked before the update. try adding this to your appium options :disableIdLocatorAutocompletion
Set the value to true

#com.rd.appname:id/FilterIconbutton","24f24ea5-7578-4152-8f4e-4b5e64ece043 is not in my code why is it adding the #

Added
appiumOptions.AddAdditionalAppiumOption("disableIdLocatorAutocompletion","true");
but it did not seem to change anything.

On Tue, Nov 21, 2023, 3:19 PM Dor Blayzer @.***> wrote:

So I think I know your issue of it worked before the update. try adding
this to your appium options :disableIdLocatorAutocompletion
Set the value to true


Reply to this email directly, view it on GitHub
#697 (comment),
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABGVOYNKU3HKR5PSY5AMMLDYFUEGHAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGYYTSOBRGI
.
You are receiving this because you were mentioned.Message ID:
@.***>

True as a boolean

Same.

...
Private AppiumElement GeteElement(By by)
{
  return _driver.FindElement(by)
...
Setup{

should be

Private AppiumElement GeteElement(MobileBy by)

?

I'm not so familiar with .net, but the error was probably the code did not use Appium's findElement. It used Selenium client's one.

public abstract class MobileBy : By

Can you confirm that you are using appium 2 server with dotnet client 5.0?
Have you tried using Accessibility ID selector BTW?

Yeah it's probably using the selenium client find logic as Kazu mentioned. There is no ID locator in Selenium anymore so the client automatically converts it to use the CSS selector strategy with a value like #id

@aaronportier, you tried changing the By to MobileBy as @KazuCocoa suggested?
Also try to find the element without using your private method to see if that's indeed the issue

It could mean that your code gave OpenQA.Selenium.By instead of MobileBy thus the CSS selector behavior was expected, right? I guess _driver instance was not AndroidDriver?

@aaronportier, let's try and simplify things so you can isolate the issue.
Can you please try to find the element directly on the driver, meaning without using the method you created and currently use in your code?
Something like that i.e.

_driver.FindElement(MobileBy.Id("{your id} "));

How did you call GeteElement? Did you give MobileBy

public abstract class MobileBy : By
?
e.g.
_driver.FindElement(MobileBy.ClassName("UIAButton")).Click();

I was wondering if your code called GeteElement with OpenQA.Selenium.By

So it work that way or not?

OpenQA.Selenium.WebDriverException

What error? It would be helpful to create a new issue with the appium server log and the client error log