Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Is it possible to emulate the Firefox-console cd function and/or javascript-context-switching in selenium-webriver?

  • 1 reply
  • 1 has this problem
  • Last reply by grobber

more options

The Firefox Web Console currently (version 80.0.1 as I type this) supports Javascript-context-switching to an iframe through a cd function (albeit set to be removed), as in

var ifr = document.getElementById('frame_id'); cd(ifr);

The same goal can be accomplished

  • by selecting a different Javascript context from a drop-down menu in the upper-right corner of the Web Console, as mentioned in that bug;
  • similarly in Chrome DevTools (see also an older SO exchange on this).


Is it possible to achieve the same effect while driving Firefox headless with selenium-webdriver?


I have a page loading a cross-origin iframe I have no control over, and would like to access DOM elements under that iframe. I can do this in the Web Console, but I have been unsuccessful in doing so via Selenium (specifically, node + the selenium-webdriver package):

Selecting the relevant iframe and then switching to it with

ifr = driver.findElement('frame_id')); driver.switchTo().frame(ifr);

gives me access to a different DOM than what I see in the Web Console: in Selenium I do not have access to the buttons, forms, etc. available in the browser when I interact with the latter directly.

Chosen solution

The answer is 'yes'. A link to the relevant Stack Overflow discussion:

Read this answer in context 👍 0

All Replies (1)

more options

Chosen Solution

The answer is 'yes'. A link to the relevant Stack Overflow discussion: