1

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, try (def d (execute-script "var n = document.body.getElementsByTagName(\"*\").length; return n;")) and a count on that returns 5.

Why is webdriver auto-filtering my results? The custom element hangout-module is not returned.

  • There is a typo in your webdriver code fragment. Perhaps you meant this: (def d (execute-script "var n = document.body.getElementsByTagName(\"*\").length; return n;")) – user246 Jan 8 '16 at 1:21
  • 1
    Which driver are you using? – user246 Jan 8 '16 at 1:23
  • Thanks for spotting that. I'm using RemoteWedDriver but the same behaviour was present in FF – raven Jan 9 '16 at 5:01
  • It looks as if that element is added dynamically. I wonder if you're calling getElementsByTagName before hangout-module exists. Adding a sleep beforehand might help determine if that's the problem. – user246 Jan 9 '16 at 15:28
  • Can you try and check whether WebdriverJS reads the element at all or not. Would you try isDisplayed, or try to find the element by xpath or id or CSS and assert whether it is present(read by Webdriver) or not? – IAmMilinPatel Jan 11 '16 at 3:34
1
+100

As per the rules of W3C custom elements are registered by script using document.registerElement(). Now, it may be possible that they are declared or created before their definition is registered by the browser. For example, you can declare on the page but end up invoking document.registerElement('hangout-module') much later.

This although this is an HTML element that has a valid custom element name but haven't been registered. Due to this, the element remains an unresolved element until it is upgraded to its definition.

And it may be possible that Webdriver is not yet designed to read unresolved elements. So you might want to look in to it, whether your custom element is registered before it is declared.

Can you try and check whether WebdriverJS reads the element at all or not. Would you try isDisplayed(), or try to find the element by xpath or id or CSS and assert whether it is present(read by Webdriver) or not?

  • Thanks for your reply. I'm marking this as answered but specifically wanted to know why webdriver didn't return the same number of elements when executing javascript. Yes, I could find the element using another selector, but I wanted to use javascript. Thanks for explaining how custom elements get registered - I didn't know that – raven Jan 15 '16 at 4:58
0

getElementsByTagNameNS is an alternative means to accomplish what you are trying to do. I know that getElementsByTagName changes all values to lowercase to process. Could be its either not counting a capital letter.

Example from the API

elements = document.getElementsByTagNameNS(namespace, name)
  • There are no capital letters in the custom-element tag. Can you supply a code snippet that proves this works? – raven Jan 9 '16 at 5:00
  • The link contains syntax and usage examples but should be almost a 1/1swap – ECiurleo Jan 9 '16 at 10:07
0

I had similar problem when our designer used custom elements (with custom tag) in Angular/material. Webdriver was not able to interact with such elements (TESTacy could be right), but I did not spent much time on researching real underlying reason for this - changing the approach was much quicker :-)

I ended up tweaking design a bit, generating span elements with custom names. Webdriver was able to find and interact with elements generated such way.

Webdriver can find all elements with a given name, returns you a list, you can loop through that list and interrogate items to find which you really want by any custom rules (instead of relying on WebDriver to find you needed elements). Or as I once needed, match items from two such lists to pairs based on autogenerated IDs. It is a cool trick to have in your toolbox.

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.