Appium Unique ID's of WebElements

306 views
Skip to first unread message

Sebastian

unread,
Mar 13, 2014, 10:48:56 AM3/13/14
to appium-...@googlegroups.com
Hi everyone,

I will get straight to the point.
First of all, trying to obtain the same WebElement twice will result in objects with different ID's. For example if I do this:

WebElement playMenu = webDriver.findElement(By.xpath("//UIAElement[@name='Play menu popup root view']"));
WebElement playMenu = webDriver.findElement(By.xpath("//UIAElement[@name='Play menu popup root view']"));
System.out.println(((RemoteWebElement)playMenu).getId()); 
System.out.println(((RemoteWebElement)playMenu2).getId()); 

Will give me the following output : 

23 
24

But this isn't the biggest problem at all. The most important problem I see with the current implementation of Appium is the fact that the IDs used to refer to different elements aren't unique.
This can be tested simply by creating a WebElement instance of a closable UI element, make it disappear and then print out different attributes of the WebElement. You will see that the WebElement now refers to a totally different UI element.

Doing : 

WebElement playMenu = webDriver.findElement(By.xpath("//UIAElement[@name='Play menu popup root view']"));
System.out.println(((RemoteWebElement)
 playMenu).getId() + " | " + playMenu.getTagName() + " | " + playMenu.getAttribute("name") + " | " + playMenu.getAttribute("label") + " | " + playMenu.getAttribute("value") + " | " + playMenu.isDisplayed() + " | " + playMenu.isEnabled());

webDriver.findElement(By.xpath("//button[@name='Close play menu']")).click;    //Closes the playMenu element
System.out.println(((RemoteWebElement) playMenu).getId() + " | " + playMenu.getTagName() + " | " + playMenu.getAttribute("name") + " | " + playMenu.getAttribute("label") + " | " + playMenu.getAttribute("value") + " | " + playMenu.isDisplayed() + " | " + playMenu.isEnabled());

Will give me the following output : 
21 | UIAElement | Play menu popup root view |  |  | true | true
21 | UIAElement | HomeScreenBottomBarHomeButton | Home |  | true | true

Because of this behaviour I can't do a simple and reliable check that the PlayMenu element has disappeared.
I consider this to be a critical bug in the Appium implementation. I just wanted to put this in the discussion group in the case I am making a mistake or in case that this was already talked about and I just didn't find anything about it. 

A quote from the WebDriver documentation found at https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html : 
"Each WebElement instance must have an ID, which is distinct from the value of the DOM Element's "id" property. The ID for every WebElement representing the same underlying DOM Element must be the same. The IDs used to refer to different underlying DOM Elements must be unique within the session over the entire duration of the session."

I consider this to be one of the most important concepts in a WebDriver implementation and I really don't understand why Appium doesn't respect it.

Do you guys know of this issue? Does it affect your tests in any way? Did you find ways to overcome this? Do you work on fixing this? Am I just wrong ?  
Got lots of questions about this, so I would appreciate any talk on the subject.


Jonathan Lipps

unread,
Mar 14, 2014, 12:48:28 AM3/14/14
to Sebastian, appium-...@googlegroups.com
That's odd, I've never seen that before. Are you able to make a repro case with either TestApp or UICatalog (those are our test apps)?

You're absolutely right that appium should never reuse IDs. Multiple IDs for the same element isn't a problem though, you can always call elementEqualsElement to determine if two ids refer to the same element.

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Sebastian

unread,
Mar 14, 2014, 12:46:41 PM3/14/14
to appium-...@googlegroups.com, Sebastian

I was able to reproduce this on the Java JUnit example by adding the following test case :

@Test
    public void testUniqueID() throws Exception {
        final WebElement firstNavigationBar = driver.findElement(By.xpath("//navigationBar[@name='UICatalog']"));
        System.out.println(((RemoteWebElement) firstNavigationBar).getId() + " | " + firstNavigationBar.getTagName() + " | " + firstNavigationBar.getAttribute("name") + " | " + firstNavigationBar.getAttribute("label") + " | " + firstNavigationBar.getAttribute("value") + " | " + firstNavigationBar.isDisplayed() + " | " + firstNavigationBar.isEnabled());
        driver.findElement(By.xpath("//tableview/cell[@name='Buttons, Various uses of UIButton']")).click();
        try {
            // Animation
            Thread.sleep(1000);
        }
        catch (Exception ignored){}
        System.out.println(((RemoteWebElement) firstNavigationBar).getId() + " | " + firstNavigationBar.getTagName() + " | " + firstNavigationBar.getAttribute("name") + " | " + firstNavigationBar.getAttribute("label") + " | " + firstNavigationBar.getAttribute("value") + " | " + firstNavigationBar.isDisplayed() + " | " + firstNavigationBar.isEnabled());
    }
 
 Output I got was :
0 | UIANavigationBar | UICatalog |  |  | true | true
0 | UIANavigationBar | Buttons |  |  | true | true

Again, same thing : 2 different elements with the same ID.
 

Sebastian

unread,
Mar 14, 2014, 12:47:50 PM3/14/14
to appium-...@googlegroups.com, Sebastian
Forgot to say that I used the UICatalogTest.

Sebastian

unread,
Mar 19, 2014, 10:56:38 AM3/19/14
to appium-...@googlegroups.com, Sebastian

I submitted an issue with the unique ID problem. 
The multiple ID for the same element is indeed not such a big deal.

Reply all
Reply to author
Forward
0 new messages