Cant find element despite the exact same locators


Im new to the tool.

The result on the left was a test case I made a couple of days ago.
The result on the right was done yesterday.

When I reran the first test case yesterday, the steps failed when attempting to search for the field; even the magnifying locater failed to pinpoint it.

I recreated the steps again in another test case for comparison and that was the result. This one ran successfully.
Literally, the only difference between the 2 is an extra step detailing me clicking on the actual element itself.(and maybe some factoring of parameters)

Am I doing something wrong here or is this a known issue?

Hello @erik.yeow and welcome to our community!
In the photos you sent I can only see an element’s locators
I need more details on the case so I can help you troubleshoot the issue.
What is the error you get?
When do you receive it?
What website are you are using?
Can you share screenshots / videos / test reports?

It’s a site Im working on with a simple login screen with 2 textboxes asking for a username and password.

I made another run with the problematic test case and I got an error message:

Failed to switch driver context to [CSSSELECTOR·=·username]

for this specific field and I dont know what it means.

Hi @erik.yeow,
That means your chosen element is inside an iFrame most likely.
Usually the recorder automatically records iFrame context, however if you created the step manually,
You need to navigate to advanced settings and add the iFrame context in which the driver should search the element in.
Let me know if you managed.

Sample image:

Well…I tried and check as per suggestion.
The source problem was the Context fields as highlighted.
But the issues seems to be as a result of there being data in them(as opposed to being blank as per the example screenshot). Both username and password fields were the same.
Once I removed all the Context data, the testcase for the fields started working again.

For the record, all the test cases I’ve build were done using the ‘Record’ function, not manually inputted, as its complex enough that Im still not familiar enough with it.

Hi @erik.yeow,
If your website contains an iFrame removing the iFrame context might not be the best idea,
If an iFrame is recorded but you must remove it in order for the test to work, can you please send us a URL where the mentioned issue is reproducing?

Im running my codes on a local server at the moment, so no, I cant send a link.

@erik.yeow okay I see,
Then please make sure your iFrames are not dynamically generated, if they are,
You might need to manually create a dynamic locator that includes all the possible iFrames and use these context on your steps.
It is possible that because the iFrame is dynamically generated the test only works in the recorder, and when you run the test a new iFrame is genertated causing the “failed to switch context” issue that you have encountered.
I have also included 2 articles on dynamic locators and how to build advanced locators below:


This topic was automatically closed after 180 days. New replies are no longer allowed.