11# Prohibit use of invalid Tag Name value when using ` by.tagName() ` locator
22
3- Ensure a valid Tag Name is being used with ` by.tagName() ` locator. [ A valid Tag Name] ( https://www.w3.org/TR/html/syntax.html#tag-name ) should only
4- contain alphanumeric and cannot start with a number.
3+ Ensure a valid Tag Name is being used with ` by.tagName() ` locator.
4+ The rule supports [ HTML specifications] ( (https://www.w3.org/TR/html/syntax.html#tag-name) ) and
5+ Angular's ability to create custom elements via directives. A Tag Name is considered valid when:
6+
7+ - It can contain alphanumeric characters.
8+ - It can contain the dash` (-) ` symbol.
9+ - It cannot start with dash or a number.
10+ - It cannot end with dash.
511
612This rule is very useful for notifying when an invalid Tag Name is being used.
713It will also prevent unintentionally putting different types of locators instead of the actual Tag name.
@@ -18,6 +24,8 @@ element(by.tagName("multiple tagnames"));
1824element (by .tagName (' option[value="Test"]' ));
1925element (by .tagName (" div " ));
2026element (by .tagName (" 12345" ));
27+ element (by .tagName (" -" ));
28+ element (by .tagName (" customtag-" ));
2129```
2230
2331The following patterns are not errors:
@@ -31,4 +39,5 @@ element(by.tagName("Area"));
3139element (by .tagName (" BlockQuote" ));
3240element (by .tagName (" h1" ));
3341element (by .tagName (" H1" ));
42+ element (by .tagName (" my-custom-tag" ));
3443```
0 commit comments