3

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

  • 1
    Can you please give example of custom element? – Helping Hands Dec 7 '15 at 3:47
  • 1
    We 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. Dec 7 '15 at 14:59
  • @PeterMasiar I don't have control or influence over the codebase – raven Dec 8 '15 at 4:56
  • Re: "but what if the elements aren't known?". Can you give an example? – dzieciou Dec 8 '15 at 13:37
3

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.

  • 1
    Thanks but that still doesn't answer why it's not included in the spec. This is a workaround. – raven Dec 8 '15 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. – ECiurleo Dec 9 '15 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? – raven Dec 11 '15 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 – ECiurleo Dec 11 '15 at 9:22
  • 1
    Done sqa.stackexchange.com/questions/16091/… – raven Dec 13 '15 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.