Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case sensivity for attribute selectors #507

Closed
p0deje opened this issue Dec 22, 2016 · 10 comments · Fixed by #856
Closed

Case sensivity for attribute selectors #507

p0deje opened this issue Dec 22, 2016 · 10 comments · Fixed by #856

Comments

@p0deje
Copy link
Member

p0deje commented Dec 22, 2016

There is a difference between CSS and XPath in case sensivity of attributes.

Having these elements on the page:

<form method="post" id="new_user" />
<form method="POST" id="delete_user" />

you can query them in browser:

> document.querySelectorAll('form[method="post"]')
< NodeList [<form id="new_user">, <form id="delete_user">] (2)

> document.querySelectorAll('form[method="POST"]')
< NodeList [<form id="new_user">, <form id="delete_user">] (2)

> $x('.//form[@method="post"]')
< [<form id="new_user">] (1)

> $x('.//form[@method="POST"]')
< [<form id="delete_user">] (1)

This comes from the fact that XPath considers attributes case sensitive while CSS does not.

Since now Watir only uses XPath selectors, using method: 'post' selector would return only one element. But when Watir is used with watir_css or watizzle gems, same selector would return two elements.

Also compare plain Selenium:

driver.find_elements(xpath: './/form[@method="post"]').count # returns 1
driver.find_elements(css: 'form[method="post"]').count       # returns 2

Since two behaviours cannot co-exist, I'm not sure what to do about it.

Related links:

@titusfortner
Copy link
Member

which would you prefer? Do we want to adjust our xpath selector to make this case independent?

@p0deje
Copy link
Member Author

p0deje commented Dec 23, 2016

I think I'd like to make it case insensitive, but I'm afraid that might break many tests, so maybe we should keep that until Watir 7.

@abotalov
Copy link
Contributor

abotalov commented Dec 1, 2017

Please note that in CSS only some attribute values are case insensitive.
For example, class / id / href are case sensitive.
It would be bad if Watir would search these (and other such attributes) case-insensitively.

@titusfortner
Copy link
Member

So, according to the spec

All attribute values are case-sensitive, except for the following:

accept
accept-charset
align
alink
axis
bgcolor
charset
checked
clear
codetype
color
compact
declare
defer
dir
direction
disabled
enctype
face
frame
hreflang
http-equiv
lang
language
link
media
method
multiple
nohref
noresize
noshade
nowrap
readonly
rel
rev
rules
scope
scrolling
selected
shape
target
text
type (except as specified in §10 Rendering)
valign
valuetype
vlink

These aren't parseable by IDL from that page, so we could hard-code this list and treat them differently.

@p0deje do you think this is worth doing?

@p0deje
Copy link
Member Author

p0deje commented Jan 28, 2019

@titusfortner Oh, how did you find that?! Yes, I think it should be straightforward to just hardcode that list (or actually parse it from spec directly - we are not limited to IDL only) and make everything these case insensitive. Do you feel like you want to do that or me?

@twalpole
Copy link

twalpole commented Jan 28, 2019

Note, those are only case insensitive on the elements they are defined for - on elements they are not defined on, or on custom elements they are case sensitive. Also most (if not all) are enumerated types so if you’re going to fix the case sensitivity, letting search for random strings doesn’t make much sense

@titusfortner
Copy link
Member

@p0dege if you could do it, it would be awesome. Especially if we can somehow use it from the html_elements file. But this is lower on my list for right now. I need to get capabilities issues fixed.

@p0deje
Copy link
Member Author

p0deje commented Feb 4, 2019

@titusfortner I'll do my best but time is pretty limited now :)

@twalpole I don't get what you mean by "enumerated types". Can you elaborate?

@twalpole
Copy link

twalpole commented Feb 5, 2019

@p0deje https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#keywords-and-enumerated-attributes - case insensitivity is for the attributes defined to be allowed a specific set of values (enumerated attributes) on specific elements - If those same attributes were used on elements they are not defined for then they should be case sensitive. Whether that's worth worrying about is debatable though.

@p0deje
Copy link
Member Author

p0deje commented Feb 9, 2019

I've prepared #856 to implement the solution, please have a look when you have time.

For now, I've just hardcoded case-insensitive attributes as I don't think it's going to change much. Otherwise, we can still add it to spec generator.

I hope I understood when attribute should be case-insensitive right 😄

p0deje added a commit that referenced this issue Feb 14, 2019
Per https://www.w3.org/TR/html52/single-page.html#casesensitivity

This commit additionally ensures that Watir ignores case of passed
selector string for attribute which case is expected to be ignored.

Closes #507
titusfortner pushed a commit that referenced this issue Aug 27, 2020
Per https://www.w3.org/TR/html52/single-page.html#casesensitivity

This commit additionally ensures that Watir ignores case of passed
selector string for attribute which case is expected to be ignored.

Closes #507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants