iframe Handling issue with wait_until and .html Methods

38 Views Asked by At

Watir: 7.0.0 Selenium-webdriver: 4.0.0 Ruby: 3.0.6 Os: MacOs Version 14.4 (23E214) Latest Firefox and geckodriver

require 'watir'
Selenium::WebDriver.logger.level = :info

class TestFFIssueWatir
  def initialize
    @browser = Watir::Browser.new :firefox
  end

  def goto_website
    @browser.goto('https://demo.automationtesting.in/Frames.html')
  end

  def close_browser
    @browser.close
  end

  # This method will demo FF issue with iframe handling when using method like wait_until.
  # Here once you use wait_until say on iframe a, then you can use only one operation on it. Eg: below send_keys will fail on second attempt after that.
  def check_error_using_wait_until
    # Locate the iframe by its ID
    top_dialog = @browser.body
    testIframe = top_dialog.iframe(id: 'singleframe')

    # Since I used this; now only one operation can be performed on the iframe. Eg: below send_keys will fail on second attempt after that
    testIframe.wait_until(timeout: 10, &:present?)

    # Try to interact with the iframe again using the original method
    testIframe.input.send_keys('Hello, Universe!')
    testIframe.input.send_keys('Hello, Again!')

    sleep(10)
  end
end

test_watir = TestFFIssueWatir.new
test_watir.goto_website
test_watir.check_error_using_wait_until
test_watir.close_browser

Issue Details

check_error_using_wait_until_fix In the method mentioned above, the code functions until testIframe.input.send_keys('Hello, Universe!'), after which it stops working. To execute the last line of code testIframe.input.send_keys('Hello, Again!'), I need to reassign the iframe testIframe = top_dialog.iframe(id: 'singleframe') again.

This is what i get in debugging log

RemoteError.sys.mjs:8:8\nWebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:191:5\nNoSuchFrameError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:570:5\nswitchToFrame@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:567:15\nreceiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:154:31\n"}}
2024-02-13 12:13:00 INFO Selenium -> GET session/fc12f525-e753-4b0c-ba1b-11e49a461139/element/c42da6c3-bbf3-4619-9818-d7c47ba559d3/css/staleness_check
2024-02-13 12:13:00 INFO Selenium <- {"value":""}
2024-02-13 12:13:00 INFO Selenium -> POST session/fc12f525-e753-4b0c-ba1b-11e49a461139/frame
2024-02-13 12:13:00 INFO Selenium    >>> http://127.0.0.1:4445/session/fc12f525-e753-4b0c-ba1b-11e49a461139/frame | {"id":{"element-6066-11e4-a52e-4f735466cecf":"c42da6c3-bbf3-4619-9818-d7c47ba559d3"}}
2024-02-13 12:13:00 INFO Selenium <- {"value":{"error":"no such frame","message":"Unable to locate frame for element: [object HTMLIFrameElement]","stacktrace":"RemoteError@chrome://remote/content/shared/

*In Chrome I am getting stale element if i use .html on same element twice *

require 'watir'
Selenium::WebDriver.logger.level = :debug
@browser = Watir::Browser.new :chrome
@browser.goto('https://demo.automationtesting.in/Frames.html')
testIframe = @browser.body.iframe(name: 'SingleFrame')
puts(testIframe.html) 
puts(testIframe.html) 

Here second .HTML gives an error stale element reference: stale element not found (Selenium::WebDriver::Error::StaleElementReferenceError)

first .html prints the element but second print throws an error : 0x0000000100984524 chromedriver + 3966244: no such element: element not found (Selenium::WebDriver::Error::NoSuchElementError) please check attached screenshot

I was able to use these methods in older versions of web browsers, but I am unable to do the same with the latest updates of web browsers. Is anyone else facing a similar issue?

0

There are 0 best solutions below