TestProject Forum

New "Failed to switch driver context to..." error for iframe elements

Using Chrome 93.0.4577.63 and Windows Agent v3.2.0, I am seeing the following error for tests attempting to locate elements within an iframe (the actual xpath location is redacted here and throughout):

Metadata: [Message]: Failed to switch driver context to XPATH = <xpath_location>

Using Chrome 92.0.4515.131 and Windows Agent v3.1.0 I could get the same job to pass. I haven’t edited the tests inbetween runs.

In a brand new test using the smart web recorder, I’ve attempted the following:

  • locate the iframe in locator (reportedly a Generic Web Element), create a new element and add a “Switch to iFrame” step with it, using the Element Extensions addon. This passes.
  • select a present div inside an iframe → Validations → “Is Present?”, this creates a test step
  • run that newly created test step, it fails with:

Failed to switch driver context to {{XPATH = /<xpath_location>

I see this error whether I run the “switch to iframe” step or not. I didn’t need this step when my tests passed a month ago on v3.1.0. I can locate the elements in the iframe manually using their css selectors, xpaths etc.

I have searched the docs (and this forum) for this error. I can’t make use of these docs because I can’t use ID as a locator option.

I’d appreciate any help I could get on this! Has something changed recently with switching context and handling iframes?

Hi,
@heather_uhs please upgrade to agent 3.3.0 and let me know if that solves your issue.

1 Like

I have the same issue and I’m using Agent 3.3.0

1 Like

I am still seeing this issue on V3.3.0 as well.
I can recreate the test steps that are failing to find iframe elements and they pass, but the old test steps are still failing.

So in order to work around this issue, I’m looking at having to recreate all previously created test steps

I’ve since discovered that the full xpath location to the iframe has changed. This was automatically being stored as the context for the test steps using iframe elements. So I can get my tests to pass if I update the context for every test step I’ve previously created.

I’ve created a feature request for more flexibility around test context: Add flexibility to test step context

Hi @heather_uhs @sally.buchanan,
The error “failed to switch driver context” probably stems from changing iFrames, when you create a step on the Recorder if this step is inside an iframe, a context is being recorded (XPath for the iFrame) when the XPaths of the iFrames are changing during execution the driver is failing to switch to the context because that iFrame is no longer exist (its locator is invalid)
Please try to analyze your application and understand what is changing in the context.
You can use this action to add healing capabilities to switching to the iFrame or even add parameters inside your locators.

image

Let me know if you have any questions.