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

fix: gracefully handle unloaded iframes #133

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open

Conversation

AdnoC
Copy link
Contributor

@AdnoC AdnoC commented Oct 18, 2023

Closes Issue: #88

@AdnoC AdnoC marked this pull request as ready for review October 23, 2023 18:00
@AdnoC AdnoC requested a review from a team as a code owner October 23, 2023 18:00
@AdnoC AdnoC marked this pull request as draft October 23, 2023 18:12
@AdnoC AdnoC marked this pull request as ready for review October 23, 2023 18:37
try
{
string partialRes = (string)_webDriver.ExecuteAsyncScript(EmbeddedResourceProvider.ReadEmbeddedFile("runPartial.js"), context, options);
// Important to deserialize because we want to reserialize as an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this comment be preserved?



// Don't go any deeper if we are just doing top-level iframe
if (runOptions.Iframes != false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked the return early approach this had before

{
// get the proper selector the frame and switch to it
var selector = _webDriver.ExecuteScript(EmbeddedResourceProvider.ReadEmbeddedFile("shadowSelect.js"), JsonConvert.SerializeObject(context.Selector, AxeJsonSerializerSettings.Default));
_webDriver.SwitchTo().Frame(selector as IWebElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally the switchTo of an unloaded iframe is the thing that puts selenium into a bad state, which means trying to switch back to the parent iframe doesn't work. This is the point where the code is needed to switch to the main window then down into the nested frames again.

Since that is not happening and this catches the error and does not rethrow it for the nested call to RunPartialRecursive, does that mean that selenium can handle unloaded iframes without erroring without all this code change?

frameStack
));
}
catch (WebDriverTimeoutException)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch will probably never be hit as you've added try/catches around almost all other other bits of this code that don't rethrow the error.

@AdnoC AdnoC dismissed straker’s stale review October 25, 2023 12:50

slight refectoring based on comments

foreach (var frameSelector in frameStack)
{
var selector = _webDriver.ExecuteScript(EmbeddedResourceProvider.ReadEmbeddedFile("shadowSelect.js"), JsonConvert.SerializeObject(frameSelector, AxeJsonSerializerSettings.Default));
if (selector is IWebElement el)
Copy link
Contributor

@straker straker Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this if statement is false? You never switch to the frame so the next frameSelector is not valid for the next frame. Do we expect this to ever be false?

Copy link
Contributor

@straker straker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants