Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find any labels using XCUIElementTypeStaticText #196

Open
arielelkin opened this issue Feb 27, 2023 · 8 comments
Open

Can't find any labels using XCUIElementTypeStaticText #196

arielelkin opened this issue Feb 27, 2023 · 8 comments

Comments

@arielelkin
Copy link
Contributor

I'm trying to assert that the text in the label says "Hello, world!"

image

import pytest

from appium import webdriver
from appium.options.mac import Mac2Options
from appium.webdriver.common.appiumby import AppiumBy

@pytest.fixture()
def driver():
    options = Mac2Options()
    options.bundle_id = 'com.example.myapp'
    drv = webdriver.Remote('http://127.0.0.1:4723', options=options)
    yield drv
    drv.quit()

def test_edit_text(driver):
    print(driver.page_source)
    my_label = driver.find_element(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeStaticText')
    assert(my_label.text == "Hello, world!")

This fails with the following error:

FAILED tester.py::test_edit_text - AssertionError: assert 'AppiumTestApp' == 'Hello, world!'

But the textfield is definitely in the page source!

<?xml version="1.0" encoding="UTF-8"?>
<XCUIElementTypeApplication elementType="2" identifier="" label="" title="AppiumTestApp" enabled="false" selected="false" x="0" y="0" width="0" height="0">
  <XCUIElementTypeWindow elementType="4" identifier="AppiumTestApp.ContentView-1-AppWindow-1" label="" title="AppiumTestApp" enabled="false" selected="false" x="390" y="313" width="900" height="450">
    <XCUIElementTypeGroup elementType="3" identifier="" label="" title="" enabled="false" selected="false" x="390" y="313" width="900" height="450">
      <XCUIElementTypeImage elementType="43" identifier="" label="Globe" title="" enabled="true" selected="false" x="831" y="520" width="18" height="17"/>
      <XCUIElementTypeStaticText elementType="48" identifier="" value="Hello, world!" label="" title="" enabled="true" selected="false" x="802" y="538" width="76" height="17"/>

Here's the very small demo app I'm trying to test:
https://github.com/arielelkin/macostestapp

@jlipps
Copy link
Member

jlipps commented Feb 27, 2023

It's possible that get text is retrieving the label attribute. You could try using the get attribute command and getting the value attribute instead? Just a thought. I haven't used this driver before.

@arielelkin
Copy link
Contributor Author

I've tried following your suggestion in a couple of ways.

1

    my_label = driver.find_element(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeStaticText')
    assert(my_label.value == "Hello, world!")

Produces this error message

FAILED tester.py::test_edit_text - AttributeError: 'WebElement' object has no attribute 'value'

2

    my_label = driver.find_element(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeStaticText')
    assert(my_label.get_attribute('text') == "Hello, world!")

Produces this error message

FAILED tester.py::test_edit_text - selenium.common.exceptions.InvalidArgumentException: Message: The att...

@jlipps
Copy link
Member

jlipps commented Feb 28, 2023

did you try

my_label.get_attribute('value`)

?

@arielelkin
Copy link
Contributor Author

    my_label = driver.find_element(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeStaticText')
    assert(my_label.get_attribute('value') == "Hello, world!")

Produces this error:

FAILED tester.py::test_edit_text - AssertionError: assert 'AppiumTestApp' == 'Hello, world!'

Which is weird, it looks like driver.find_element(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeStaticText') retrieves the entire app?

@jlipps
Copy link
Member

jlipps commented Mar 2, 2023

That doesn't seem right unless your app has accessibility text configured incorrectly. @mykola-mokhnach I'm not sure where to go from here given I don't use this driver. Any ideas on your end?

@mykola-mokhnach
Copy link
Contributor

I don't see any issues there. We display exactly what XCTest returns to us. If some values are not present then either a wrong element is located or XCTest fetches unexpected values for it

@arielelkin
Copy link
Contributor Author

@jlipps @mykola-mokhnach

The app I'm testing is just Xcode's macOS App template, but it's as bare-bones as can be (except for the TextField I've added but which really shouldn't be interfering)

Are you able to reproduce the issue? Here's the small demo app:
https://github.com/arielelkin/macostestapp

@arielelkin
Copy link
Contributor Author

@jlipps @mykola-mokhnach following up on this 😃

I was wondering if you were able to reproduce the issue? Or have any suggestions as to why the XCUIElementTypeStaticText identifier isn't working..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants