Why aren't custom tags supported yet in Selenium WebDriver? I realise the W3C web components proposal is still under review, but browsers are already implementing them widely (angular apps come to mind e.g. ng-app
).
-
1Can you please give example of custom element?– Helping HandsDec 7, 2015 at 3:47
-
1We use Angular, and I ask developers to add names or IDs to relevant generated elements 9or do it myself). Selenium webdriver has no problem finding them, so not sure what is your problem.– Peter M. - stands for MonicaDec 7, 2015 at 14:59
-
@HelpingHands html5rocks.com/en/tutorials/webcomponents/customelements– ravenDec 8, 2015 at 4:54
-
@PeterMasiar I don't have control or influence over the codebase– ravenDec 8, 2015 at 4:56
-
Re: "but what if the elements aren't known?". Can you give an example?– dzieciouDec 8, 2015 at 13:37
1 Answer
You can find custom elements by using the tagName;
Example of how to find an element that looks like this:
<iframe src="..."></iframe>
would be
WebElement frame = driver.findElement(By.tagName("iframe"));
Full documentation is available on the Selenium API
I would also suggest you maintain a separate list (or Enum) of your custom elements as they are dynamically generated so easily changed in the code base which could lead to a high number of tests needing updating.
-
1Thanks but that still doesn't answer why it's not included in the spec. This is a workaround.– ravenDec 8, 2015 at 19:32
-
This example is the official way of finding an element by tag name (custom or otherwise). I am not quite sure what you mean by it not being in the spec.– ECiurleoDec 9, 2015 at 9:50
-
Fair enough, accept that may have not come across clearly. Here's a simple scenario. Navigate to the custom elements example, open a console and type in
document.body.getElementsByTagName("*").length
- you should get 6 returned as the result. Using webdriver, I try(def d (execute-script "var n = document.body.getElementsByTagName(\"*\"); return n;"))
and a count on that returns 5. Why is webdriver filtering my results?– ravenDec 11, 2015 at 5:26 -
I see what you mean. I would suggest you post that as a separate question as I am sure someone will know the answer (I don't at this point). My only thought is n being defined as a base 0 value– ECiurleoDec 11, 2015 at 9:22
-
1