MinkSelenium2Driver icon indicating copy to clipboard operation
MinkSelenium2Driver copied to clipboard

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

Open jepster opened this issue 4 years ago • 11 comments

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: https://github.com/nightwatchjs/nightwatch/issues/2135

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

jepster avatar Feb 04 '20 10:02 jepster

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 https://github.com/nightwatchjs/nightwatch/issues/2135#issuecomment-503975296). 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.

aik099 avatar Feb 04 '20 10:02 aik099

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

cwdt avatar Apr 09 '20 09:04 cwdt

Same problem here

rushhourmedia avatar Jun 04 '20 11:06 rushhourmedia

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.

ChrisTaylorDeveloper avatar Jun 13 '20 22:06 ChrisTaylorDeveloper

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 avatar Jan 27 '21 12:01 BramDriesen

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.

BramDriesen avatar Jan 27 '21 13:01 BramDriesen

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...

Chekote avatar Aug 26 '21 14:08 Chekote

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

larowlan avatar Jan 14 '22 01:01 larowlan

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

Gamesh avatar Jan 30 '23 07:01 Gamesh

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();
  }

AlexSkrypnyk avatar Feb 11 '23 06:02 AlexSkrypnyk

The issue will be fixed in https://github.com/minkphp/MinkSelenium2Driver/pull/382.

aik099 avatar Feb 24 '24 17:02 aik099