SeleniumHQ / selenium-ide

Open Source record and playback test automation for the web.
https://selenium.dev/selenium-ide/
Apache License 2.0
2.73k stars 739 forks source link

Select frame by index not selecting the right frame if there're lazy loaded frames #847

Open melode11 opened 4 years ago

melode11 commented 4 years ago

šŸ› Bug Report

Selenium IDE will record incorrect index for iframe if there're lazy loaded frames (e.g. google ads) on the page. When playback, selenium IDE is able to select the recorded iframe but the command line runner will not.

Below sample side file, on w3schools tryit page, the google ads is the 0th iframe while the html display area is the 1st iframe. Both IDE recording and playback missed the google ads iframe and treated the html display area the 0th iframe. But Selenium Command line runner will pick google ads iframe correctly. Seems the iframe order in selenium IDE are determined by frame load time while iframe order in selenium command line runner are detemined by the position of the iframe in the page at the time the select frame command is executed.

{ "id": "b6e07d0e-4153-bbd7-304d-57e022a6c5b9", "version": "2.0", "name": "google", "url": "https://www.w3schools.com/tags/tryit.asp", "tests": [{ "id": "7b22e685-f0f2-4769-a1be-66d35ee15266", "name": "test", "commands": [{ "id": "a6f5ab07-74ae-4292-bf64-797a51b7ff35", "comment": "", "command": "open", "target": "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_target", "targets": [], "value": "" }, { "id": "20d716aa-99c8-4d2a-a3a5-230a0552a559", "comment": "", "command": "setWindowSize", "target": "1789x1004", "targets": [], "value": "" }, { "id": "1ed38b40-5309-481f-9afc-e6570313269c", "comment": "", "command": "selectFrame", "target": "index=0", "targets": [ ["index=0"] ], "value": "" }, { "id": "6435567e-6761-4410-af40-14580c579fd9", "comment": "", "command": "storeTitle", "target": "", "targets": [], "value": "frametitle" }, { "id": "0606f56d-04da-46ea-aed0-a213c9b1c714", "comment": "", "command": "echo", "target": "frametitle", "targets": [], "value": "" }, { "id": "cf835eb5-a506-4745-a9a6-b4af22205305", "comment": "", "command": "click", "target": "linkText=Visit W3Schools!", "targets": [ ["linkText=Visit W3Schools!", "linkText"], ["css=a", "css:finder"], ["xpath=//a[contains(text(),'Visit W3Schools!')]", "xpath:link"], ["xpath=//a[contains(@href, 'https://www.w3schools.com')]", "xpath:href"], ["xpath=//a", "xpath:position"], ["xpath=//a[contains(.,'Visit W3Schools!')]", "xpath:innerText"] ], "value": "", "opensWindow": true, "windowHandleName": "win6407", "windowTimeout": 2000 }, { "id": "96fb5991-2778-4b3c-a850-38086e3d260e", "comment": "", "command": "selectWindow", "target": "handle=${win6407}", "targets": [], "value": "" }] }], "suites": [{ "id": "cfbddc3f-0a6e-4bee-88d8-07fcbb0071a5", "name": "Default Suite", "persistSession": false, "parallel": false, "timeout": 300, "tests": ["7b22e685-f0f2-4769-a1be-66d35ee15266"] }], "urls": ["https://google.com/", "https://www.w3schools.com/tags/att_a_target.asp", "https://www.w3schools.com/tags/tryit.asp"], "plugins": [] }

To Reproduce

Steps to reproduce the behavior: See above side file

Expected behavior

Select correct frame index should be recorded, or css locator should be recorded for select frame.

Project file reproducing this issue (highly encouraged)

See above side content.

Environment

OS: Windows 10 Selenium IDE Version: 3.14.0 Selenium SIDE Runner Version: 3.14.0 Please note that selenium-side-runner supports Node.js 8 - 10 --> Node version: v10.16.3 Browser: Google Chrome Browser Version: 77.0.3865.120

skyboyer commented 4 years ago

I'm looking into https://github.com/SeleniumHQ/selenium-ide/blob/master/packages/side-runtime/src/webdriver.js#L201 and it looks like it should allow selecting frame by CSS selector. That that could be a workaround(because of implicit wait in waitForElement). But trying to use frame locator as css=#preview I'm ending with "Failed: invalid argument" Or is it irrelevant package?

corevo commented 4 years ago

@skyboyer you are looking into the code of the next major version of Selenium IDE, that version will support selecting frames by locators.

The current version now in production does not, you can view that code by going to the v3 branch.

rahulkar commented 3 years ago

@corevo Hi, Can you please mention which files we need to modify so that Selenium IDE while recording will capture frame by id/name/xpath instead of index? For now I am okay if it only works with same-origin policy.

corevo commented 3 years ago

Its a hefty change, you'll have to edit both content scripts and background scripts, the entire communication channel between frames and the IDE is based on indexes and ids.

Start by looking into the background recorder and the recorder in the content scripts.