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

Headless Chrome 79: Cannot switch to IFrame due "frame: invalid argument: 'id' can not be string" #315

Open
jepster opened this issue Feb 4, 2020 · 11 comments

Comments

@jepster
Copy link

jepster commented Feb 4, 2020

Hi,

I am trying to switch into an iframe, but I cannot in the current headless Chrome version. Looks like a faulty interface is being used in the following method which accepts a string, but should accept an (DOM)-object:

\Behat\Mink\Driver\Selenium2Driver::switchToIFrame()

Since I am getting the following error from my Chromedriver:

And I switch to the "entity_browser_iframe_media_browser" frame: invalid argument: 'id' can not be string
  (Session info: headless chrome=79.0.3945.117)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'd3ef7b5a8c17', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.78-coreos', java.version: '1.8.0_232'
Driver info: driver.version: unknown (Exception)

Other testing libraries are also complying about such a change: nightwatchjs/nightwatch#2135

Do you know how to solve that? Is there any updated version is the build?

@aik099
Copy link
Member

aik099 commented Feb 4, 2020

According to JsonWireProtocol (see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidframe) the frame name/id is a valid value. Not sure what ChromeDriver specifically doesn't like about it.

The issue might w3c mode specific and you can try changing w3c mode via driver options (see nightwatchjs/nightwatch#2135 (comment)). Another option to try is also suggested in above referenced comment.

Also try using master branch of the driver to see if issue was fixed.

@cwdt
Copy link

cwdt commented Apr 9, 2020

Did you find a solution for this problem? I'm experiencing the same issue and can't get it to work.

@rushhourmedia
Copy link

Same problem here

@ChrisTaylorDeveloper
Copy link

I have the same problem with this Docker image selenium/standalone-chrome-debug i.e. no version number so I assume 'latest'. When I use selenium/standalone-chrome-debug:3.141.59-neon everything is fine.

@BramDriesen
Copy link

Interesting, I encountered the same issue while being on the latest beta version (4.0.0-beta-1-prerelease-20210114), downgrading to the most recent 3.x version (3.141.59) also didn't fix the issue. Switching to the neon version 3.141.59-neon did also solve the issue for me

@BramDriesen
Copy link

I tested a bit more, and selenium/standalone-chrome-debug:3.141.59-oxygen also does work, but everything after that version will not work.

@Chekote
Copy link
Contributor

Chekote commented Aug 26, 2021

I had a similar problem using selenium/standalone-chrome-debug:3.141.59-20210804 when trying to call switchToWindow(). No matter what I pass it throws an exception stating invalid argument: 'handle' must be a string.

I switched to selenium/standalone-chrome-debug:3.141.59-oxygen as @BramDriesen suggested and it worked (thanks, you're a lifesaver). But I guess we either need to get to the bottom of this, or something needs to be fixed on the Selenium side so we can move forward at some point...

@larowlan
Copy link

For those here, make sure you're passing w3c: false in your chrome options when creating the driver.

@Gamesh
Copy link

Gamesh commented Jan 30, 2023

can anyone elaborate is it an issue on MinkSelenium driver or selenium or chrome driver?

@AlexSkrypnyk
Copy link

Works with numerical ID being the index of the iframe on the page:

 /**
   * Assert that content is present in an iframe.
   *
   * @Then I see content in iframe with id :id
   */
  public function iSeeContentInIframe($id) {
    $driver = $this->getSession()->getDriver();
    if (!$driver instanceof Selenium2Driver) {
      throw new RuntimeException('Unsupported driver for this step');
    }

    $index = NULL;

    $iframe_elements = $driver->find('//iframe');
    if (!empty($iframe_elements)) {
      foreach ($iframe_elements as $k => $all_page_iframe_element) {
        if ($all_page_iframe_element->getAttribute('id') == $id) {
          $index = $k;
          break;
        }
      }
    }

    if (is_null($index)) {
      throw new ElementNotFoundException($driver, 'iFrame', $id);
    }

    $driver->switchToIFrame($index);

    if (!$driver->find('//body')) {
      throw new Exception(sprintf('The contents of the iFrame with id "%s" was not loaded', $id));
    }

    // Reset frame to the default window.
    $driver->switchToIFrame();
  }

@aik099
Copy link
Member

aik099 commented Feb 24, 2024

The issue will be fixed in #382.

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

No branches or pull requests

10 participants