-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Advanced CSS selectors eg. :contains('John') #60
Comments
Thanks, the |
Thank you for your quick answer. Unfortunately it doesn't work. I have to wait for XPATH implementation ther #33. Thanks. P. |
Just to let you know, this is also discussed on the mailing list and someone had managed to achieve this with xpath: https://groups.google.com/forum/#!topic/nightwatchjs/d0p72Ub9Idg |
Perfect 👍 I vote for :contains() (it will keeps a simplicity and beauty of Nightwatch.js). later you can add a XPATH support. |
+1 for :contains |
+1 : Finding elements in collections by nth-child is too brittle, :contains() would be 👍 |
👎 i would vote agains :contains() as @beatfactor already mentioned
and go for real XPath support instead.. Just my two cents |
Without native browser css support, this it won't probably be implemented. I could look into delegating to jQuery (if available) via |
+1 for :contains - as this is a very widely used selector that makes for infinitely simpler to read code than the mess of troubleshooting that appears to be required to get the equivalent messier xpath queries working in nightwatch on even a basic level |
+1 for |
+1 |
If you happen to use jquery in your site, you can use https://github.com/maxgalbu/nightwatch-custom-commands-assertions |
+1 |
1 similar comment
+1 |
@maxgalbu -- Awesome! Thanks for all of these; very useful. |
+1 |
8 similar comments
👍 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
@beatfactor Does Nightwatch support |
@montogeek I don't think so. They are pseudo in CSS. jQuery doesn't even support to query them. |
@yumikohey Yep, I ended testing the element in a different way |
+1 |
1 similar comment
+1 |
+1 :contains FYI and just to reconfirm - a[text='blah'] does not work in jQuery or Nightwatch. Looks like I also have to resort to the clunkiness of XPath. :-( |
+1 |
An alternative would be to convert your CSS selectors to XPath using css2xpath. An added benefit is that you can use CSS/XPath selector hybrids:
which converts to:
It also supports :icontains for case insensitive matching, reverse combinators (!>, ! , !^, !+, !~), :starts-with, :ends-with, :first, :last, :has, :has-(sibling|child|ancestor), etc. You can use the live css2xpath demo to test your selectors. For more information on what it can do, you can check out the source or contribute some documentation. |
var c2x = require('css2xpath');
...
browser
.useXpath()
.click(c2x(':contains("Log in")')) |
+1 |
@beatfactor - I would like to suggest to add support for extended CSS selector for selecting elements with specific text. Similar to JQuery http://api.jquery.com/contains-selector/. It would be usefull for testing worflow. Eg. for testing of creating / updating / deleting records.
browser.click("ul li a:contains('Record')");
or
browser.click("ul li a[text='Record']");
Maybe XPath selectors could handle it?
Thank you!
Btw. Nightwatch.js is cool :-)
The text was updated successfully, but these errors were encountered: