selenium.commonexceptions.InvalidSelectorException: Message: Locator Strategy 'class name is not supported for this session

Viewed 37

I am trying to automate a desktop application on Windows 10 with the following stack: Python + Appium + WinAppDriver. I use the Gherkin language and Page Object Pattern.

After run feature file I have error output:

selenium.common.exceptions.InvalidSelectorException: Message: Locator Strategy 'class name,PasswordBox[@text='txtPassword']' is not supported for this session
      Stacktrace:
      InvalidSelectorError: Locator Strategy 'class name,PasswordBox[@text='txtPassword']' is not supported for this session
          at WindowsDriver.validateLocatorStrategy (C:\Users\mm\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js
:393:13)

I tried to build xpath using ClassName and text but it does not work. I tried to located this element also by id, name and there is the same error.

I use Inspect.exe tool to locate elements on desktop application.

My code:

login_page.py

from selenium.webdriver.common.by import By
from appium import webdriver
from page.base_page import BasePage


class AdminLoginPage(BasePage):

    pwd_2 = (By.CLASS_NAME, "PasswordBox[@text='txtPassword']")


    def __int__(self, driver):
        super().__init__(driver)

    def click_pwd_field(self):
        self.click(self.pwd_2)

The AdminLoginPage class inherits from the BasePage class. In BasePage class I described all action which user can perform on element e.g click, input, scroll

environment.py

from appium import webdriver
from app.application import Application


def before_scenario(context, scenario):
    desired_capabilities = {
        "platform": "Windows",
        "platformVersion": "10",
        "app": "C:\Program Files (x86)\path\path\app.exe"
    }

    context.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_capabilities=desired_capabilities)
    context.driver.implicitly_wait(3)
    context.app = Application(context.driver)

application.py

from page.login_page import AdminLoginPage

class Application:

    def __init__(self, driver):
        self.admin_login_page = AdminLoginPage(driver)

steps.py

from behave import *

@step('I click pwd field')
def click_pwd_field(context):
    context.app.admin_login_page.click_pwd_field()

appium 1.22.3 java version "1.8.0_333" selenium 4.4.3

Inspect tool

1 Answers

"PasswordBox[@text='txtPassword']" is not a class name, it is a CSS_SELECTOR.
Try to change it to

pwd_2 = (By.CSS_SELECTOR, "PasswordBox[@text='txtPassword']")

Also, I'm not sure it will work since only XPath supports selecting elements based on their text content, not CSS Selectors

Related