find raises Javascript error
yoavCodemonkey opened this issue · 10 comments
Meta
Capybara Version:
3.39.2
Driver Information (and browser if relevant):
selenium-webdriver 3.142.7 with chrome
Expected Behavior
find should return element and not raise an error
Actual Behavior
Failure/Error: Unable to infer file and line number from backtrace
Selenium::WebDriver::Error::JavascriptError:
javascript error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
(Session info: chrome=115.0.5790.170)
# 0 chromedriver 0x00000001032af6b8 chromedriver + 4937400
# 1 chromedriver 0x00000001032a6b73 chromedriver + 4901747
# 2 chromedriver 0x0000000102e64616 chromedriver + 435734
# 3 chromedriver 0x0000000102e69adf chromedriver + 457439
# 4 chromedriver 0x0000000102e6c9bf chromedriver + 469439
# 5 chromedriver 0x0000000102ee7bce chromedriver + 973774
# 6 chromedriver 0x0000000102ecc012 chromedriver + 860178
# 7 chromedriver 0x0000000102ee6e76 chromedriver + 970358
# 8 chromedriver 0x0000000102ecbde3 chromedriver + 859619
# 9 chromedriver 0x0000000102e99d7f chromedriver + 654719
# 10 chromedriver 0x0000000102e9b0de chromedriver + 659678
# 11 chromedriver 0x000000010326b2ad chromedriver + 4657837
# 12 chromedriver 0x0000000103270130 chromedriver + 4677936
# 13 chromedriver 0x0000000103276def chromedriver + 4705775
# 14 chromedriver 0x000000010327105a chromedriver + 4681818
# 15 chromedriver 0x000000010324392c chromedriver + 4495660
# 16 chromedriver 0x000000010328e838 chromedriver + 4802616
# 17 chromedriver 0x000000010328e9b7 chromedriver + 4802999
# 18 chromedriver 0x000000010329f99f chromedriver + 4872607
# 19 libsystem_pthread.dylib 0x00007ff801a99259 _pthread_start + 125
# 20 libsystem_pthread.dylib 0x00007ff801a94c7b thread_start + 15
Steps to reproduce
calling find when element is found, e.g find('#instructions-ok')
error seems to be raised in Capybara Element code
That error would imply that 'window' doesn't exist, are you closing the window in your test, or a previous test? Also the version of selenium-webdriver you're using is really old, please upgrade
I am not closing the test browser window.
Upgraded to selenium 4.9.0, the issue persists.
I would think the error implies that 'this' (the parameter sent to getComputedStyle) is not of the expected type (Element) in that js scope
Ok, so what exactly is your test doing. Nobody else has reported this issue and it's not new code
I've simplified it to this:
feature 'test', js: true do
it 'works' do
admin = create(:admin)
allow_any_instance_of(ApplicationController).to receive(:current_user) { admin }
visit "challenges/1"
find('#instructions-ok')
end
end
What is the element with id instructions-ok?
It's a div.
This error is happening throughout our test suite, it's not related to a specific element/page.
Then I'd guess you've got something that has inserted itself into Capybaras normal flow since nobody else is reporting this behavior. If you can show a stacktrace which shows the code being executed there might be something there, otherwise you're going to need to debug it and figure out what style
is being called with, and why -- I don't believe this is an issue in Capybara
OK debugged it -
getComputedStyle is called with document passed as argument, which raises the mentioned error.
This comes from Capybara isShown which traverses the display list looking for parent with display none.
There is a guard there for not calling getComputedStyle with Document, but it does not work -- here, Node.DOCUMENT_NODE is undefined..
Please do check further.
@yoavCodemonkey What environment are you running in that Node.DOCUMENT_NODE
is not defined? It's been part of the DOM standard forever ... https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
Right, that's the problem, some library class is shadowing native Node..
Thanks for your responsiveness on this!