appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
381 stars 187 forks source link

All Android Tests I now get a CSS Selector exception for #697

Closed aaronportier closed 10 months ago

aaronportier commented 10 months ago

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.

KazuCocoa commented 10 months ago

How did you create the driver instance? Perhaps the typical case is the driver is not AndroidDriver nor iOSDriver. e.g. https://github.com/search?q=repo%3Aappium%2Fdotnet-client+AndroidDriver+path%3A%2F%5Etest%5C%2Fintegration%5C%2F%2F+path%3A%2F%5Etest%5C%2Fintegration%5C%2FAndroid%5C%2F%2F&type=code

Dor-bl commented 10 months ago

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

aaronportier commented 10 months ago

Here is the code using the driver and more on the error below: Public Android driver _driver; ... Private AppiumElement GeteElement(By by) { return _driver.FindElement(by) ... Setup{ _driver= new Android driver(new URi("url"), appiumOptions); When I run test in my cloud provider it shows the error using css selector value #com.rd.appname:id/FilterIconbutton Response css selector is not supported. However it should be looking for MobileBy.Id(com.rd.appname:id/FilterIconbutton

On Tue, Nov 21, 2023, 1:12 PM Dor Blayzer @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1821420422, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYPF64PY7GHTEOW6BGLYFTVKTAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGQZDANBSGI . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 10 months ago

@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

aaronportier commented 10 months ago

It's an id but the error message states css Selector which I have never used that's part of why it's so confusing. I have found changing the id to XPath seems to not generate the error but I don't want everything to use XPath.

On Tue, Nov 21, 2023, 2:43 PM Dor Blayzer @.***> wrote:

@aaronportier https://github.com/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

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1821573163, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYK6TI3LWG6IXTMF3KLYFT77FAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGU3TGMJWGM . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 10 months ago

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.

aaronportier commented 10 months ago

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.

aaronportier commented 10 months ago

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

Dor-bl commented 10 months ago

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

aaronportier commented 10 months ago

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

aaronportier commented 10 months ago

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 https://github.com/appium/dotnet-client/issues/697#issuecomment-1821619812, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYNKU3HKR5PSY5AMMLDYFUEGHAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGYYTSOBRGI . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 10 months ago

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 https://github.com/appium/dotnet-client/issues/697#issuecomment-1821619812, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYNKU3HKR5PSY5AMMLDYFUEGHAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGYYTSOBRGI . You are receiving this because you were mentioned.Message ID: @.***>

True as a boolean

aaronportier commented 10 months ago

Same.

KazuCocoa commented 10 months ago
...
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.

https://github.com/appium/dotnet-client/blob/db85e3c088f81b786787817a0f1db82fdfc33158/src/Appium.Net/Appium/MobileBy.cs#L23

Dor-bl commented 10 months ago

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

jlipps commented 10 months ago

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 commented 10 months ago

What's the best way to fix it? I use lots of ID's in my app?

On Tue, Nov 21, 2023, 5:22 PM Jonathan Lipps @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1821794783, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYMYRGSRHPLJMWK2R6DYFUSRHAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRG44TINZYGM . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 10 months ago

@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

aaronportier commented 10 months ago

The error I get when changing public AppiumElement GeteElement(Mobile by) { return _driver.FindElement(by); } I get Argument 1:cannot convert from OpenQA.Selenium.By to AppiumTestingofmobileapps.MobileBy

On Tue, Nov 21, 2023, 9:46 PM Dor Blayzer @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1822003378, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYL7N36NNDYYW54CBZDYFVRPLAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRSGAYDGMZXHA . You are receiving this because you were mentioned.Message ID: @.***>

KazuCocoa commented 10 months ago

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 commented 10 months ago

Sorry I am not sure what you think is wrong? You think this is incorrect: Public Android driver _driver; _driver= new AndroidDriver(new URi("url"), appiumOptions); The above should be calling AndroidDriver The public AppiumElement GeteElement(By by) {return _driver.findElement(by)

On Mon, Nov 27, 2023, 12:43 PM Kazuaki Matsuo @.***> wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1828323932, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYLYOVBJGMQMBI26OWDYGTGNNAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYGMZDGOJTGI . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 10 months ago

@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} "));

KazuCocoa commented 10 months ago

How did you call GeteElement? Did you give MobileBy https://github.com/appium/dotnet-client/blob/499530ca25e496321db7fef8314c888e9ae883ad/src/Appium.Net/Appium/MobileBy.cs#L23 ? e.g. https://github.com/appium/dotnet-client/blob/499530ca25e496321db7fef8314c888e9ae883ad/test/integration/IOS/WebviewTest.cs#L46

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

aaronportier commented 10 months ago

If I don't use IDs and just use XPath and Accessibility IDs it mostly runs to the end. I can see it pass in BrowserStack but Visual Studio fails OpenQA.Selenium.WebDriverException : The executeScript command returned an unexpected error.(the same happens in my iOS tests) It passes in Debug. I tried changes in the configuration manager and still it fails. Is the above related to the ID's not working?

On Mon, Nov 27, 2023, 2:40 PM Aaron Portier @.***> wrote:

Sorry I am not sure what you think is wrong? You think this is incorrect: Public Android driver _driver; _driver= new AndroidDriver(new URi("url"), appiumOptions); The above should be calling AndroidDriver The public AppiumElement GeteElement(By by) {return _driver.findElement(by)

On Mon, Nov 27, 2023, 12:43 PM Kazuaki Matsuo @.***> wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1828323932, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYLYOVBJGMQMBI26OWDYGTGNNAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYGMZDGOJTGI . You are receiving this because you were mentioned.Message ID: @.***>

aaronportier commented 10 months ago

Yes I use MobileBy to find the elements. _driver.FindElement(MobileBy.Id("com.rd.app:id/New-Image")));

On Mon, Nov 27, 2023, 2:53 PM Kazuaki Matsuo @.***> wrote:

How did you call GeteElement? Did you give MobileBy https://github.com/appium/dotnet-client/blob/499530ca25e496321db7fef8314c888e9ae883ad/src/Appium.Net/Appium/MobileBy.cs#L23 ? e.g. https://github.com/appium/dotnet-client/blob/499530ca25e496321db7fef8314c888e9ae883ad/test/integration/IOS/WebviewTest.cs#L46

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

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1828499970, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYJ27MLGSXCFB6GJZYDYGTVR5AVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYGQ4TSOJXGA . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 10 months ago

So it work that way or not?

aaronportier commented 10 months ago

No it still does not work.

You are asking if it's okay to not use ID's and only run tests in Debug mode? I would prefer it worked the way it used to. Seems like a step down.

On Mon, Nov 27, 2023, 3:07 PM Dor Blayzer @.***> wrote:

So it work that way or not?

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1828509756, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYOQJBKCJNZ62QAIBWTYGTXHTAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYGUYDSNZVGY . You are receiving this because you were mentioned.Message ID: @.***>

aaronportier commented 10 months ago

Okay I changed the following and it appears to allow for ID's _driver.Findelement(ById.Id("com.rd.app:id/New-Image")).

I still get the OpenQA.Selenium.WebDriverException : The executeScript command returned an unexpected error in Visual Studio though.

On Mon, Nov 27, 2023, 3:41 PM Aaron Portier @.***> wrote:

No it still does not work.

You are asking if it's okay to not use ID's and only run tests in Debug mode? I would prefer it worked the way it used to. Seems like a step down.

On Mon, Nov 27, 2023, 3:07 PM Dor Blayzer @.***> wrote:

So it work that way or not?

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/697#issuecomment-1828509756, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYOQJBKCJNZ62QAIBWTYGTXHTAVCNFSM6AAAAAA7U3UIMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYGUYDSNZVGY . You are receiving this because you were mentioned.Message ID: @.***>

KazuCocoa commented 10 months ago

OpenQA.Selenium.WebDriverException

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