Capybara unable to pick up hidden element









up vote
0
down vote

favorite












Pretty simple spec is failing after upgrade (Rails 4.2 -> 5.2) and Capybara (2.x to 3.10.1).



I think it might have something to do with the way .hover is being used to make a hidden element appear on mouseover, but I could be wrong?!?



The "1" bubble appears when driver is manually paused right before "expect(…)" . However, I'm not sure Capybara's .hover is working in the spec. Is there any other way to do do this?



RSpec:



scenario 'changes counter' do
close_modal type: :image

find('editable-section:nth-child(1) li.photo:nth-child(1)').hover

save_and_open_page # <- `1` is visible on the page (see HTML below)

within 'editable-section:nth-child(1) li.photo:nth-child(1)' do
expect(page).to have_css '.comment-count', text: '1'
end
end


Failure:



 1) Comment creation for image changes counter
Failure/Error: expect(page).to have_css '.comment-count', text: '1'
expected to find visible css ".comment-count" with text "1" within #<Capybara::Node::Element tag="li" path="/HTML/BODY/DIV[2]/SECTION/DIV/EDITABLE-SECTION[1]/DIV/DIV/DIV/SECTION/UL/LI"> but there were no matches. Also found "", which matched the selector but not all filters.


It doesn't even respond to:



pry> expect(page).to have_css('.comment-count')
RSpec::Expectations::ExpectationNotMetError: expected to find visible css ".comment-count" but there were no matches. Also found "", "", "", which matched the selector but not all filters.


HTML from Chrome paused right before expect shows that .comment-count is clearly there:



<ul attachments="section.attachments" class="collage ng-scope ng-isolate-scope" image-collage="" ng-if="isDisplaying">
<!-- ngRepeat: attachment in section.attachments -->
<li class="photo ng-scope" ng-repeat="attachment in section.attachments" style="width: 299px; height: 300px; margin-bottom: 9.6px; margin-right: 0px; display: inline-block; vertical-align: bottom; overflow: hidden; opacity: 1;">
<div class="meta-indicator">
<div class="comment-count">
<i class="fa fa-comment"></i>
<span ng-bind="attachment.commentsCount" class="ng-binding">1</span>
</div>
</div>
<a class="image-wrapper" href="">
<img ng-click="openModal(attachment)" ng-src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" role="button" tabindex="0" src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" style="width: 299px; height: 300px;">
</a>
</li>
<!-- end ngRepeat: attachment in section.attachments -->
</ul>


CSS (slim):



 ul.collage(image-collage attachments="section.attachments" ng-if="isDisabled")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
)

ul.collage(image-collage attachments="section.attachments" ng-if="isDisplaying")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
ng-click="openModal(attachment)"
)


Edit: Add Chrome dev inspection



What's happening if I stop the test after find('...').hover the element is visible but the element is not revealed. If i manually hover the mouse at this point or force a :hover (as seen in image) then the test proceeds immediately and passes.



It is finding the element, as replacing .hover with .click opens the modal. Something about .hover is not working. Is that any other way to automate a :hover event?



enter image description here










share|improve this question























  • As asked on your previous question about the same issue which you didn't respond to - What do you have Capybara.default_max_wait_time set to?
    – Thomas Walpole
    Nov 11 at 1:11






  • 1




    Also - you can't trust save_and_open_page for visibility issues, because it saves HTML attributes not properties, and isn't always able to load the CSS. Instead just pause your test and look at the browser to see whether the count is visible. The error message is telling you that it's finding 3 elements that match `.comment-count' but they are not visible or the text doesn't match '1' -- are you sure you're selecting within the correct element (maybe add more of the HTML to the question)??
    – Thomas Walpole
    Nov 11 at 1:16











  • default_max_wait_time = 10
    – Meltemi
    Nov 11 at 1:19










  • Ok -- you show two different error messages - one has "" and one has "","","" - so one is finding one element that matches '.comment-count' and the other is finding 3 (none are actually visible though) -- why the difference?
    – Thomas Walpole
    Nov 11 at 1:21











  • How is the visibility handled? Is it through CSS or is it via a JS library? If JS what events is it dependent on?
    – Thomas Walpole
    Nov 11 at 1:23














up vote
0
down vote

favorite












Pretty simple spec is failing after upgrade (Rails 4.2 -> 5.2) and Capybara (2.x to 3.10.1).



I think it might have something to do with the way .hover is being used to make a hidden element appear on mouseover, but I could be wrong?!?



The "1" bubble appears when driver is manually paused right before "expect(…)" . However, I'm not sure Capybara's .hover is working in the spec. Is there any other way to do do this?



RSpec:



scenario 'changes counter' do
close_modal type: :image

find('editable-section:nth-child(1) li.photo:nth-child(1)').hover

save_and_open_page # <- `1` is visible on the page (see HTML below)

within 'editable-section:nth-child(1) li.photo:nth-child(1)' do
expect(page).to have_css '.comment-count', text: '1'
end
end


Failure:



 1) Comment creation for image changes counter
Failure/Error: expect(page).to have_css '.comment-count', text: '1'
expected to find visible css ".comment-count" with text "1" within #<Capybara::Node::Element tag="li" path="/HTML/BODY/DIV[2]/SECTION/DIV/EDITABLE-SECTION[1]/DIV/DIV/DIV/SECTION/UL/LI"> but there were no matches. Also found "", which matched the selector but not all filters.


It doesn't even respond to:



pry> expect(page).to have_css('.comment-count')
RSpec::Expectations::ExpectationNotMetError: expected to find visible css ".comment-count" but there were no matches. Also found "", "", "", which matched the selector but not all filters.


HTML from Chrome paused right before expect shows that .comment-count is clearly there:



<ul attachments="section.attachments" class="collage ng-scope ng-isolate-scope" image-collage="" ng-if="isDisplaying">
<!-- ngRepeat: attachment in section.attachments -->
<li class="photo ng-scope" ng-repeat="attachment in section.attachments" style="width: 299px; height: 300px; margin-bottom: 9.6px; margin-right: 0px; display: inline-block; vertical-align: bottom; overflow: hidden; opacity: 1;">
<div class="meta-indicator">
<div class="comment-count">
<i class="fa fa-comment"></i>
<span ng-bind="attachment.commentsCount" class="ng-binding">1</span>
</div>
</div>
<a class="image-wrapper" href="">
<img ng-click="openModal(attachment)" ng-src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" role="button" tabindex="0" src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" style="width: 299px; height: 300px;">
</a>
</li>
<!-- end ngRepeat: attachment in section.attachments -->
</ul>


CSS (slim):



 ul.collage(image-collage attachments="section.attachments" ng-if="isDisabled")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
)

ul.collage(image-collage attachments="section.attachments" ng-if="isDisplaying")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
ng-click="openModal(attachment)"
)


Edit: Add Chrome dev inspection



What's happening if I stop the test after find('...').hover the element is visible but the element is not revealed. If i manually hover the mouse at this point or force a :hover (as seen in image) then the test proceeds immediately and passes.



It is finding the element, as replacing .hover with .click opens the modal. Something about .hover is not working. Is that any other way to automate a :hover event?



enter image description here










share|improve this question























  • As asked on your previous question about the same issue which you didn't respond to - What do you have Capybara.default_max_wait_time set to?
    – Thomas Walpole
    Nov 11 at 1:11






  • 1




    Also - you can't trust save_and_open_page for visibility issues, because it saves HTML attributes not properties, and isn't always able to load the CSS. Instead just pause your test and look at the browser to see whether the count is visible. The error message is telling you that it's finding 3 elements that match `.comment-count' but they are not visible or the text doesn't match '1' -- are you sure you're selecting within the correct element (maybe add more of the HTML to the question)??
    – Thomas Walpole
    Nov 11 at 1:16











  • default_max_wait_time = 10
    – Meltemi
    Nov 11 at 1:19










  • Ok -- you show two different error messages - one has "" and one has "","","" - so one is finding one element that matches '.comment-count' and the other is finding 3 (none are actually visible though) -- why the difference?
    – Thomas Walpole
    Nov 11 at 1:21











  • How is the visibility handled? Is it through CSS or is it via a JS library? If JS what events is it dependent on?
    – Thomas Walpole
    Nov 11 at 1:23












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Pretty simple spec is failing after upgrade (Rails 4.2 -> 5.2) and Capybara (2.x to 3.10.1).



I think it might have something to do with the way .hover is being used to make a hidden element appear on mouseover, but I could be wrong?!?



The "1" bubble appears when driver is manually paused right before "expect(…)" . However, I'm not sure Capybara's .hover is working in the spec. Is there any other way to do do this?



RSpec:



scenario 'changes counter' do
close_modal type: :image

find('editable-section:nth-child(1) li.photo:nth-child(1)').hover

save_and_open_page # <- `1` is visible on the page (see HTML below)

within 'editable-section:nth-child(1) li.photo:nth-child(1)' do
expect(page).to have_css '.comment-count', text: '1'
end
end


Failure:



 1) Comment creation for image changes counter
Failure/Error: expect(page).to have_css '.comment-count', text: '1'
expected to find visible css ".comment-count" with text "1" within #<Capybara::Node::Element tag="li" path="/HTML/BODY/DIV[2]/SECTION/DIV/EDITABLE-SECTION[1]/DIV/DIV/DIV/SECTION/UL/LI"> but there were no matches. Also found "", which matched the selector but not all filters.


It doesn't even respond to:



pry> expect(page).to have_css('.comment-count')
RSpec::Expectations::ExpectationNotMetError: expected to find visible css ".comment-count" but there were no matches. Also found "", "", "", which matched the selector but not all filters.


HTML from Chrome paused right before expect shows that .comment-count is clearly there:



<ul attachments="section.attachments" class="collage ng-scope ng-isolate-scope" image-collage="" ng-if="isDisplaying">
<!-- ngRepeat: attachment in section.attachments -->
<li class="photo ng-scope" ng-repeat="attachment in section.attachments" style="width: 299px; height: 300px; margin-bottom: 9.6px; margin-right: 0px; display: inline-block; vertical-align: bottom; overflow: hidden; opacity: 1;">
<div class="meta-indicator">
<div class="comment-count">
<i class="fa fa-comment"></i>
<span ng-bind="attachment.commentsCount" class="ng-binding">1</span>
</div>
</div>
<a class="image-wrapper" href="">
<img ng-click="openModal(attachment)" ng-src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" role="button" tabindex="0" src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" style="width: 299px; height: 300px;">
</a>
</li>
<!-- end ngRepeat: attachment in section.attachments -->
</ul>


CSS (slim):



 ul.collage(image-collage attachments="section.attachments" ng-if="isDisabled")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
)

ul.collage(image-collage attachments="section.attachments" ng-if="isDisplaying")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
ng-click="openModal(attachment)"
)


Edit: Add Chrome dev inspection



What's happening if I stop the test after find('...').hover the element is visible but the element is not revealed. If i manually hover the mouse at this point or force a :hover (as seen in image) then the test proceeds immediately and passes.



It is finding the element, as replacing .hover with .click opens the modal. Something about .hover is not working. Is that any other way to automate a :hover event?



enter image description here










share|improve this question















Pretty simple spec is failing after upgrade (Rails 4.2 -> 5.2) and Capybara (2.x to 3.10.1).



I think it might have something to do with the way .hover is being used to make a hidden element appear on mouseover, but I could be wrong?!?



The "1" bubble appears when driver is manually paused right before "expect(…)" . However, I'm not sure Capybara's .hover is working in the spec. Is there any other way to do do this?



RSpec:



scenario 'changes counter' do
close_modal type: :image

find('editable-section:nth-child(1) li.photo:nth-child(1)').hover

save_and_open_page # <- `1` is visible on the page (see HTML below)

within 'editable-section:nth-child(1) li.photo:nth-child(1)' do
expect(page).to have_css '.comment-count', text: '1'
end
end


Failure:



 1) Comment creation for image changes counter
Failure/Error: expect(page).to have_css '.comment-count', text: '1'
expected to find visible css ".comment-count" with text "1" within #<Capybara::Node::Element tag="li" path="/HTML/BODY/DIV[2]/SECTION/DIV/EDITABLE-SECTION[1]/DIV/DIV/DIV/SECTION/UL/LI"> but there were no matches. Also found "", which matched the selector but not all filters.


It doesn't even respond to:



pry> expect(page).to have_css('.comment-count')
RSpec::Expectations::ExpectationNotMetError: expected to find visible css ".comment-count" but there were no matches. Also found "", "", "", which matched the selector but not all filters.


HTML from Chrome paused right before expect shows that .comment-count is clearly there:



<ul attachments="section.attachments" class="collage ng-scope ng-isolate-scope" image-collage="" ng-if="isDisplaying">
<!-- ngRepeat: attachment in section.attachments -->
<li class="photo ng-scope" ng-repeat="attachment in section.attachments" style="width: 299px; height: 300px; margin-bottom: 9.6px; margin-right: 0px; display: inline-block; vertical-align: bottom; overflow: hidden; opacity: 1;">
<div class="meta-indicator">
<div class="comment-count">
<i class="fa fa-comment"></i>
<span ng-bind="attachment.commentsCount" class="ng-binding">1</span>
</div>
</div>
<a class="image-wrapper" href="">
<img ng-click="openModal(attachment)" ng-src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" role="button" tabindex="0" src="https://d545dpp7432ym.cloudfront.net/images/medium/test-image.jpg" style="width: 299px; height: 300px;">
</a>
</li>
<!-- end ngRepeat: attachment in section.attachments -->
</ul>


CSS (slim):



 ul.collage(image-collage attachments="section.attachments" ng-if="isDisabled")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
)

ul.collage(image-collage attachments="section.attachments" ng-if="isDisplaying")
li.photo ng-repeat="attachment in section.attachments"
.meta-indicator
.comment-count
i.fa.fa-comment
span ng-bind="attachment.commentsCount"

a.image-wrapper href=""
img(
ng-src=" attachment.mediaFile.previewUrl('medium') "
ng-click="openModal(attachment)"
)


Edit: Add Chrome dev inspection



What's happening if I stop the test after find('...').hover the element is visible but the element is not revealed. If i manually hover the mouse at this point or force a :hover (as seen in image) then the test proceeds immediately and passes.



It is finding the element, as replacing .hover with .click opens the modal. Something about .hover is not working. Is that any other way to automate a :hover event?



enter image description here







ruby-on-rails rspec hover capybara selenium-chromedriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 21:52

























asked Nov 11 at 0:56









Meltemi

20.9k42168256




20.9k42168256











  • As asked on your previous question about the same issue which you didn't respond to - What do you have Capybara.default_max_wait_time set to?
    – Thomas Walpole
    Nov 11 at 1:11






  • 1




    Also - you can't trust save_and_open_page for visibility issues, because it saves HTML attributes not properties, and isn't always able to load the CSS. Instead just pause your test and look at the browser to see whether the count is visible. The error message is telling you that it's finding 3 elements that match `.comment-count' but they are not visible or the text doesn't match '1' -- are you sure you're selecting within the correct element (maybe add more of the HTML to the question)??
    – Thomas Walpole
    Nov 11 at 1:16











  • default_max_wait_time = 10
    – Meltemi
    Nov 11 at 1:19










  • Ok -- you show two different error messages - one has "" and one has "","","" - so one is finding one element that matches '.comment-count' and the other is finding 3 (none are actually visible though) -- why the difference?
    – Thomas Walpole
    Nov 11 at 1:21











  • How is the visibility handled? Is it through CSS or is it via a JS library? If JS what events is it dependent on?
    – Thomas Walpole
    Nov 11 at 1:23
















  • As asked on your previous question about the same issue which you didn't respond to - What do you have Capybara.default_max_wait_time set to?
    – Thomas Walpole
    Nov 11 at 1:11






  • 1




    Also - you can't trust save_and_open_page for visibility issues, because it saves HTML attributes not properties, and isn't always able to load the CSS. Instead just pause your test and look at the browser to see whether the count is visible. The error message is telling you that it's finding 3 elements that match `.comment-count' but they are not visible or the text doesn't match '1' -- are you sure you're selecting within the correct element (maybe add more of the HTML to the question)??
    – Thomas Walpole
    Nov 11 at 1:16











  • default_max_wait_time = 10
    – Meltemi
    Nov 11 at 1:19










  • Ok -- you show two different error messages - one has "" and one has "","","" - so one is finding one element that matches '.comment-count' and the other is finding 3 (none are actually visible though) -- why the difference?
    – Thomas Walpole
    Nov 11 at 1:21











  • How is the visibility handled? Is it through CSS or is it via a JS library? If JS what events is it dependent on?
    – Thomas Walpole
    Nov 11 at 1:23















As asked on your previous question about the same issue which you didn't respond to - What do you have Capybara.default_max_wait_time set to?
– Thomas Walpole
Nov 11 at 1:11




As asked on your previous question about the same issue which you didn't respond to - What do you have Capybara.default_max_wait_time set to?
– Thomas Walpole
Nov 11 at 1:11




1




1




Also - you can't trust save_and_open_page for visibility issues, because it saves HTML attributes not properties, and isn't always able to load the CSS. Instead just pause your test and look at the browser to see whether the count is visible. The error message is telling you that it's finding 3 elements that match `.comment-count' but they are not visible or the text doesn't match '1' -- are you sure you're selecting within the correct element (maybe add more of the HTML to the question)??
– Thomas Walpole
Nov 11 at 1:16





Also - you can't trust save_and_open_page for visibility issues, because it saves HTML attributes not properties, and isn't always able to load the CSS. Instead just pause your test and look at the browser to see whether the count is visible. The error message is telling you that it's finding 3 elements that match `.comment-count' but they are not visible or the text doesn't match '1' -- are you sure you're selecting within the correct element (maybe add more of the HTML to the question)??
– Thomas Walpole
Nov 11 at 1:16













default_max_wait_time = 10
– Meltemi
Nov 11 at 1:19




default_max_wait_time = 10
– Meltemi
Nov 11 at 1:19












Ok -- you show two different error messages - one has "" and one has "","","" - so one is finding one element that matches '.comment-count' and the other is finding 3 (none are actually visible though) -- why the difference?
– Thomas Walpole
Nov 11 at 1:21





Ok -- you show two different error messages - one has "" and one has "","","" - so one is finding one element that matches '.comment-count' and the other is finding 3 (none are actually visible though) -- why the difference?
– Thomas Walpole
Nov 11 at 1:21













How is the visibility handled? Is it through CSS or is it via a JS library? If JS what events is it dependent on?
– Thomas Walpole
Nov 11 at 1:23




How is the visibility handled? Is it through CSS or is it via a JS library? If JS what events is it dependent on?
– Thomas Walpole
Nov 11 at 1:23

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244900%2fcapybara-unable-to-pick-up-hidden-element%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244900%2fcapybara-unable-to-pick-up-hidden-element%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党