Hmm I can't duplicate this, but... If you do not want returning elements from a JavaScript call to be automatically translated into Watir elements, you can do:
b.wd.execute_script On Thu, Oct 4, 2018, 2:26 AM Sam Nissen <[email protected]> wrote: > Hi Titus, I can replicate this: > > # Set your browser language to en-uk > b = Watir::Browser.new :chrome > b.goto "https://rakutenmarketing.com/en-uk/" > b.span(text: /LEARN MORE/i).click > b.execute_script("return dataLayer;") > Selenium::WebDriver::Error::StaleElementReferenceError: stale element > reference: element is not attached to the page document > (Session info: chrome=69.0.3497.100) > (Driver info: chromedriver=2.35.528157 ( > 4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.6 x86_64 > ) > from /path/.rvm/gems/ruby-2.4.1/gems/selenium-webdriver-3.14.0/lib/ > selenium/webdriver/remote/bridge.rb:164:in `execute' > from > /path/.rvm/gems/ruby-2.4.1/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/oss/bridge.rb:584:in > `execute' > from > /path/.rvm/gems/ruby-2.4.1/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/oss/bridge.rb:477:in > `element_tag_name' > from /path/.rvm/gems/ruby-2.4.1/gems/selenium-webdriver-3.14.0/lib/ > selenium/webdriver/common/element.rb:86:in `tag_name' > from > /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:324:in ` > wrap_element' > from > /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:311:in > `wrap_elements_in' > from /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:315 > :in `block in wrap_elements_in' > from > /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:315:in ` > each' > from > /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:315:in > `wrap_elements_in' > from /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:313 > :in `block in wrap_elements_in' > from > /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:313:in ` > map' > from > /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:313:in > `wrap_elements_in' > from /path/.rvm/gems/ruby-2.4.1/gems/watir-6.14.0/lib/watir/browser.rb:217 > :in `execute_script' > from (irb):29 > from /path/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>' > > > > On Thursday, October 4, 2018 at 8:33:01 AM UTC+1, gary wrote: >> >> stale element reference: element is not attached to the page document >> (Session info: chrome=69.0.3497.100) >> (Driver info: chromedriver=2.37.544315 >> (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.17134 >> x86_64) >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/response.rb:69:in >> `assert_ok' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/response.rb:32:in >> `initialize' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:81:in >> `new' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:81:in >> `create_response' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:86:in >> `request' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:59:in >> `call' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:653:in >> `raw_execute' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:631:in >> `execute' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:537:in >> `element_tag_name' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/element.rb:88:in >> `tag_name' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:343:in >> `wrap_element' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:330:in >> `wrap_elements_in' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:334:in >> `block in wrap_elements_in' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:334:in >> `each' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:334:in >> `wrap_elements_in' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:332:in >> `block in wrap_elements_in' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:332:in >> `map' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:332:in >> `wrap_elements_in' >> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:261:in >> `execute_script' >> C:/temp/test1.rb:13:in `<main>' >> >> On Wednesday, 3 October 2018 15:13:57 UTC+1, Titus Fortner wrote: >>> >>> Hmm, it should be really difficult to get that exception in watir. Can >>> you provide a stack trace? >>> >>> >>> On Wed, Oct 3, 2018, 3:41 AM 'gary' via Watir General < >>> [email protected]> wrote: >>> >>>> hi, >>>> >>>> I'm having trouble converting some selenium scripts to watir, lol >>>> please don't ask me why, anyway, the basic selenium script below works a >>>> treat: >>>> >>>> require 'selenium-webdriver' >>>> $b=Selenium::WebDriver.for :chrome >>>> $b.get'mywebsite' >>>> # click cookie message overlay >>>> sleep(3) >>>> $b.find_element(:xpath=>"//*[@id='continue']").click >>>> puts $b.execute_script("return dataLayer;") >>>> >>>> >>>> the watir equivalent appears to fail: >>>> >>>> require 'watir' >>>> $b = Watir::Browser.new :chrome >>>> $b.goto('mywebsite') >>>> # click cookie message overlay >>>> sleep(3) >>>> $b.link(id: 'continue').click >>>> puts $b.execute_script("return dataLayer;") >>>> >>>> returning the following error: >>>> >>>> stale element reference: element is not attached to the page document >>>> (Selenium::WebDriver::Error::StaleElementReferenceError) >>>> >>>> >>>> does anyone know of a workaround for this or any ideas as to how to >>>> extract the relevant data? >>>> >>>> Regards, >>>> >>>> G >>>> >>>> -- >>>> -- >>>> Before posting, please read >>>> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. >>>> >>>> In short: search before you ask, be nice. >>>> >>>> [email protected] >>>> http://groups.google.com/group/watir-general >>>> [email protected] >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Watir General" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- > -- > Before posting, please read > https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. > > In short: search before you ask, be nice. > > [email protected] > http://groups.google.com/group/watir-general > [email protected] > --- > You received this message because you are subscribed to the Google Groups > "Watir General" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected] --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
