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.
"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.