Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchToFrame does not work with WebElement ID of the <iframe> #2126

Open
zsoltszakaly opened this issue Aug 7, 2023 · 2 comments
Open

SwitchToFrame does not work with WebElement ID of the <iframe> #2126

zsoltszakaly opened this issue Aug 7, 2023 · 2 comments

Comments

@zsoltszakaly
Copy link

System

  • Version: 0.33.0
  • Platform: Linux/Debian
  • Firefox: 116.0.1 (64bit)
  • Selenium: Do not use it

Testcase

File1:

<html>
  <body>
  <iframe src="html2.html">
  </body>
</html>

File2 (called html2.html)

<html>
  <body>
  Line<br>
  </body>
</html>

Stacktrace

I am using a custom application talking to the GeckoDriver through HTTP, so the client side log is not that relevant.

  1. The program first finds the <html> tag of the main document and returns its ID (ending with 95e1 in the log below) for later comparison purposes.
  2. Then it finds the ID for the <iframe> tag (...6d9e).
  3. Then it tries to SwithToFrame using the <iframe> tag WebDriver ID (i.e. the same ...6d9e). It returns an OK code (as if the context was changed).
  4. Then the <html> tag is found again. It should be the <html> of the iframe, i.e. a different ID. The assumed error that it finds again the main <html> tag and not the one in the iframe. This can be seen, that the second ID returned equals to the one before the ChangeToFrame. It is the assumed bug. Even if the SwitchToFrame could not be executed (e.g. wrong ID) then it should not return 200 OK.

In another run the same thing is done, but the ChangeFrameTo is done (step 3) using "id" with index 0. In this case it works as intended as it can also be seen in the log, returning a different ID for the <html>, this time from the iframe (...88c6).

Trace-level log

The error run

1691431487039 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/element {"using": "css selector", "value": "html"}
1691431487040 Marionette DEBUG 0 -> [0,7,"WebDriver:FindElement",{"using":"css selector","value":"html"}]
1691431487044 RemoteAgent TRACE WebDriverProcessData actor created for PID 84762
1691431487046 Marionette TRACE [11] MarionetteCommands actor created for window id 12884901889
1691431487054 Marionette DEBUG 0 <- [1,7,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"4c423f1b-e180-433d-8d91-e7dbd1ad95e1"}}]
1691431487054 webdriver::server DEBUG <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"4c423f1b-e180-433d-8d91-e7dbd1ad95e1"}}
1691431487095 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/element {"using": "css selector", "value": "iframe"}
1691431487097 Marionette DEBUG 0 -> [0,8,"WebDriver:FindElement",{"using":"css selector","value":"iframe"}]
1691431487099 Marionette DEBUG 0 <- [1,8,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"d128ee63-b2bc-4f2c-871a-bc3784aa6d9e"}}]
1691431487100 webdriver::server DEBUG <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"d128ee63-b2bc-4f2c-871a-bc3784aa6d9e"}}

1691431487144 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/frame {"element-6066-11e4-a52e-4f735466cecf": "d128ee63-b2bc-4f2c-871a-bc3784aa6d9e"}
1691431487146 Marionette DEBUG 0 -> [0,9,"WebDriver:SwitchToFrame",{"id":null}]
1691431487149 Marionette DEBUG 0 <- [1,9,null,{"value":null}]
1691431487150 webdriver::server DEBUG <- 200 OK {"value":null}
1691431487196 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/element {"using": "css selector", "value": "html"}
1691431487198 Marionette DEBUG 0 -> [0,10,"WebDriver:FindElement",{"using":"css selector","value":"html"}]
1691431487203 Marionette DEBUG 0 <- [1,10,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"4c423f1b-e180-433d-8d91-e7dbd1ad95e1"}}]
1691431487205 webdriver::server DEBUG <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"4c423f1b-e180-433d-8d91-e7dbd1ad95e1"}}

The correct run (from the point it differs)

1691433924803 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/frame {"id": 0}
1691433924804 Marionette DEBUG 0 -> [0,14,"WebDriver:SwitchToFrame",{"id":0}]
1691433924806 Marionette DEBUG 0 <- [1,14,null,{"value":null}]
1691433924806 webdriver::server DEBUG <- 200 OK {"value":null}
1691433924848 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/element {"using": "css selector", "value": "html"}
1691433924849 Marionette DEBUG 0 -> [0,15,"WebDriver:FindElement",{"using":"css selector","value":"html"}]
1691433924851 Marionette TRACE [12884901889] MarionetteCommands actor created for window id 12884901891
1691433924853 Marionette DEBUG 0 <- [1,15,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"0101b99a-43d9-4ba0-9f64-b115d2a888c6"}}]
1691433924854 webdriver::server DEBUG <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"0101b99a-43d9-4ba0-9f64-b115d2a888c6"}}

@zsoltszakaly
Copy link
Author

I found the error. It was in my code. Instead of
{"element-6066-11e4-a52e-4f735466cecf": "d128ee63-b2bc-4f2c-871a-bc3784aa6d9e"}
{"id": {"element-6066-11e4-a52e-4f735466cecf": "d128ee63-b2bc-4f2c-871a-bc3784aa6d9e"}} should have been the payload of the Switch To Frame command. I am sorry for the false alarm.
It is strange though that no error message was given.

@whimboo
Copy link
Collaborator

whimboo commented Aug 9, 2023

Thanks for the report. The failure here actually is in the following log lines:

1691431487144 webdriver::server DEBUG -> POST /session/05ce34bc-23c6-426a-a61a-3c9edf3e72da/frame {"element-6066-11e4-a52e-4f735466cecf": "d128ee63-b2bc-4f2c-871a-bc3784aa6d9e"}
1691431487146 Marionette DEBUG 0 -> [0,9,"WebDriver:SwitchToFrame",{"id":null}]

With no id specified geckodriver forwards just null. Looking at the remote end steps for Switch To Frame and specifically step 2 there is indeed a problem:

If id is not null, a Number object, or an Object that represents a web element, return error with error code invalid argument.

In the above case id is not specified in the request and as such it should indeed fail with an invalid argument error.

I'm reopening this issue and filed https://bugzilla.mozilla.org/show_bug.cgi?id=1847875 to get this fixed.

@whimboo whimboo reopened this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants