ferrum: Click on chrome invisible element not work.

Following is a example.

image

I want to click on all of “全部” in the scroll view, but only 4 of them available, there left 16 “全部” invisible, for make left ones visible, use can move scroll bar or use keyboard page down.

That is, i can find out full 20 “全部” element use click_node = popup.xpath('.//span[contains(text(), "全部")]'), but only 4 of them can click, others is not clickable, for now, i have to trigger keyboard like this:

while click on invisbile element failed  # try click again.
  instance.keyboard.type(:pagedown)
  sleep 
end

but this solution is is crisp , and error-prone, behavior not controllable.

I don’t sure if this is a issue, because i think any element which can retrieve, it should accept browser click event.

Anyway, if this is not a issue, is there exists a robust way to make one invisible element can be visible? (move scroll bar automatically), or do a function, check one element is visible?

Thank you.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Is there a way to port this feature into ferrum directly?

we wanna keep ferrum as simple as possible:

ferrum instead should be close to what real user would do with the browser. So if you can’t see a node in the viewport you can’t click on it,

https://github.com/rubycdp/ferrum/pull/141#discussion_r561893810

However, I think, it’s nice to have Ferrum::Node#in_viewport? and Ferrum::Node#scroll_into_view methods to have a simpler way to handle it without additional cuprite logic.

Also see https://stackoverflow.com/a/72717388/322020

Chrome 105 (and Edge and Opera) and Firefox 106 introduced Element.checkVisibility() which returns true if the element is visible, and false otherwise.

I’m doing some issue gardening 🌱🌿 🌷 and came upon this issue. Since it’s quite old and doesn’t seem like a problem with Ferrum (just that OP wants something that is handled by Cuprite). Maybe we can close this issue?

By closing some old issues we reduce the list of open issues to a more manageable set.

In my opinion you should scroll to element explicitely. Ferrum should not do that for you. I’m not sure I want the page to scroll without my knowledge.

That’s exactly my initial thought, Ferrum does things straightforward, no magic. Cuprite is compatible with the other drivers and has some magic inside because in Capybara you click_link and a lot of things happen. I think we can move those little missing pieces from Cuprite but we should never use them as hidden behavior on click, you should do them explicitly.

I think if you use Cuprite driver it might work because Ferrum appeared from it, and now we are in transition of things from Cuprite to Ferrum and back. First of all there’s trigger(:click) method there, and second it uses some JS to move node into viewport before clicking, Ferrum is more straightforward and doesn’t do anything for now. But it’s on my todo list