seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.45k stars 908 forks source link

open a new tab when click on iframe #2873

Closed dashng closed 6 days ago

dashng commented 6 days ago

When I record the testing script, I found an issue when I click iframe. A new page will be open to show the iframe url directly and switch to the new window automatically.

The behavior is not expected.

self.switch_to_frame('iframe[title="navigation"]')  
self.switch_to_parent_frame()                       
self.switch_to_frame('iframe[title="navigation"]')  
self.switch_to_parent_frame()                       
self.switch_to_frame('iframe[title="navigation"]')  
self.switch_to_parent_frame()                       
self.switch_to_frame('iframe[title="navigation"]')  
self.switch_to_parent_frame()                       
self.switch_to_frame('iframe[title="navigation"]') 
mdmintz commented 6 days ago

That's expected due to the Same-Origin Policy: https://en.wikipedia.org/wiki/Same-origin_policy. You cannot detect events in cross-domain iframe: https://stackoverflow.com/a/29347299/7058266. Also see https://stackoverflow.com/a/6170976/7058266 for more info.

In order to record actions from within an iframe (other than clicking on the iframe itself), the iframe must be loaded in a new tab. The Recorder will automatically open an iframe in a new tab if you click on one.

dashng commented 6 days ago

That's expected due to the Same-Origin Policy: https://en.wikipedia.org/wiki/Same-origin_policy. You cannot detect events in cross-domain iframe: https://stackoverflow.com/a/29347299/7058266. Also see https://stackoverflow.com/a/6170976/7058266 for more info.

In order to record actions from within an iframe (other than clicking on the iframe itself), the iframe must be loaded in a new tab. The Recorder will automatically open an iframe in a new tab if you click on one.

@mdmintz Thanks for your clear explanation and patience!