Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

Овај сајт ће имати ограничену функционалност док га будемо ажурирали у циљу побољшања вашег искуства. Ако неки чланак не реши ваш проблем и желите да поставите питање, на располагању ће вам бити наше заједнице подршке @FirefoxSupport на Twitter-у и /r/firefox на Reddit-у.

Претражи подршку

Избегните преваре подршке. Никада од вас нећемо тражити да зовете или шаљете поруке на број или да делите личне податке. Пријавите сумњиве радње преко „Пријавите злоупотребу” опције.

Сазнај више

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

  • 1 одговор
  • 1 има овај проблем
  • 11 прегледа
  • Последњи одговор послао 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).

Question:

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

Background:

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(By.id('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.

The Firefox [https://developer.mozilla.org/en-US/docs/Tools/Web_Console Web Console] currently (version 80.0.1 as I type this) supports Javascript-context-switching to an iframe through a cd function (albeit [https://bugzilla.mozilla.org/show_bug.cgi?id=1605327 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 [https://developers.google.com/web/tools/chrome-devtools/console/reference#context Chrome DevTools] (see also an [https://stackoverflow.com/a/8581276/11064961 older SO exchange] on this). '''Question:''' Is it possible to achieve the same effect while driving Firefox headless with [https://www.npmjs.com/package/selenium-webdriver selenium-webdriver]? '''Background:''' 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(By.id('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.

Изабрано решење

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

https://stackoverflow.com/a/63715117/11064961

Прочитајте овај одговор са објашњењем 👍 0

Сви одговори (1)

more options

Одабрано решење

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

https://stackoverflow.com/a/63715117/11064961