appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
373 stars 186 forks source link

[Bug]: By.ClassName selector for IOS Driver not working as expected #795

Closed tahmeednabi closed 2 weeks ago

tahmeednabi commented 2 weeks ago

Description

I am trying to find an element by classname, with code as shown below:

_driver = new IOSDriver(serverUri, driverOptions);
var UserNameElement = _driver.FindElement(By.ClassName("XCUIElementTypeTextField"));

However, I get an error during test run:

Error Message:
   OpenQA.Selenium.InvalidSelectorException : Unsupported CSS selector '.XCUIElementTypeTextField'. Reason: ''[object Object].XCUIElementTypeTextField'
      is not a valid ios class. Must be a single string (e.g.: XCUIElementTypeWindow) without
      dots separating them'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalid-selector-exception

For some reason, there is an [object Object] interpolated into the string selection. I think this may be a bug in the By.ClassName selector code.

Environment

Details

Please provide more details, if necessary.

Code To Reproduce Issue [ Good To Have ]

Please remember that, with sample code; it's easier to reproduce a bug and much faster to fix it. You can git clone https://github.com/appium/sample-code or https://github.com/appium/sample-code/tree/master/sample-code/apps and reproduce an issue using C# and sample apps. Also, you can create a gist with pasted C# code sample or put it here using markdown. About markdown please read Mastering markdown and Writing on GitHub

Exception stack traces

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
I am in Login Test method 
test passed web element click
  Failed LoginTest [5 s]
  Error Message:
   OpenQA.Selenium.InvalidSelectorException : Unsupported CSS selector '.XCUIElementTypeTextField'. Reason: ''[object Object].XCUIElementTypeTextField'
      is not a valid ios class. Must be a single string (e.g.: XCUIElementTypeWindow) without
      dots separating them'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalid-selector-exception
  Stack Trace:
     at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Appium.AppiumDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.WebDriver.FindElement(By by)
   at OpenQA.Selenium.Appium.AppiumDriver.FindElement(By by)
   at fpa.BaseTests.LoginTest() in /Users/tahmeednabi/Desktop/Projects/fpa-test-automation-mobile/fpa-test-automation-mobile/src/Tests/BaseTests.cs:line 60
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Link to Appium logs

Please create a gist which is a paste of your full Appium logs, and link them here. Do not paste your full Appium logs here, as it will make this issue very long and hard to read! If you are reporting a bug, always include Appium logs as linked gists! It helps to define the problem correctly and clearly.

Dor-bl commented 2 weeks ago

Does other class name values work for you?

tahmeednabi commented 2 weeks ago

Does other class name values work for you?

No, unfortunately any string I put in the By.ClassName method gives me the same error

Dor-bl commented 2 weeks ago

@tahmeednabi By.ClassName is a Selenium Selector. For Appium you should be using: MobileBy.ClassName

tahmeednabi commented 2 weeks ago

Ah, silly me! Thank you!