-
Notifications
You must be signed in to change notification settings - Fork 252
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
Add element XPath to result #77
Comments
@adelevie, opening a new issue for discussions around xpath. This would be really useful |
Potentially dumb question, but how does HTML Code Sniffer know where to place the tooltips when running a sniff? |
Each message in HTML CodeSniffer has a reference to a DOM element so I guess it just calculates where to place the tooltip based on it's dimensions and position. I did a bit of investigation into capturing screenshots of these with pa11y but it's a considerable amount of work |
I'd be less interested in screenshots, but would love to get the XPaths or CSS selectors of these elements from |
See 18F/pulse#195 for some context of my goals. |
Ah I see, well I know it'd also be really useful for pa11y-dashboard on our side, so I'll definitely get time to implement something. Do you have a preference for XPath/CSS? If they're simple enough to implement I could add both or make it configurable. |
I don't have a preference--my only goal is to be empowered to create my own HTML tooltips for "static" reports. Whichever element identifier makes that happen is what I want. Let me know if/how I can help with this. |
Here's a (horrible) proof of concept for CSS selectors. In function fullPath(el){
var names = [];
while (el.parentNode){
if (el.id){
names.unshift('#'+el.id);
break;
}else{
if (el==el.ownerDocument.documentElement) names.unshift(el.tagName);
else{
for (var c=1,e=el;e.previousElementSibling;e=e.previousElementSibling,c++);
names.unshift(el.tagName+":nth-child("+c+")");
}
el=el.parentNode;
}
}
return names.join(" > ");
}
function processMessageHtml (element) {
var outerHTML = null;
var innerHTML = null;
if (!element.outerHTML) {
return outerHTML;
}
outerHTML = element.outerHTML;
if (element.innerHTML.length > 31) {
innerHTML = element.innerHTML.substr(0, 31) + '...';
outerHTML = outerHTML.replace(element.innerHTML, innerHTML);
}
if (outerHTML.length > 251) {
outerHTML = outerHTML.substr(0, 250) + '...';
}
var css_selector = fullPath(element);
return outerHTML+" css selector: " + css_selector;
} |
Thanks @adelevie, I might tackle this tomorrow morning or Wednesday as I'm relatively free, I'd quite like to supply both CSS and XPath. Shouldn't be too complicated based on your proof of concept, I can just abstract out the element traversal and then string together XPath or CSS :) |
Great! Can you ensure that these new values are available as separate
|
Yes, I was thinking something like: {
code: 'foo',
message: 'bar',
context: 'baz',
type: 'error',
typeCode: 1,
selectors: {
xpath: '/html/body/p[0]',
css: 'html > body > p:nth-child(1)'
}
} |
Perfect!
|
@adelevie I added the CSS selector in #78, It'd be great if you had time to cast your eyes over it. I might add XPath at some point but it was proving difficult to test. The Format has changed to:
|
CSS selector added in #78. Open a new issue if XPath is required later |
See discussion in #61. This could be done quite easily in pa11y 2.0, you'd need to get each element's XPath in lib/inject (which run's within PhantomJS). You could use one of the functions in these SO answers:
The text was updated successfully, but these errors were encountered: