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

Support switching to frame by index #8

Closed
aik099 opened this issue Feb 22, 2024 · 5 comments
Closed

Support switching to frame by index #8

aik099 opened this issue Feb 22, 2024 · 5 comments

Comments

@aik099
Copy link
Member

aik099 commented Feb 22, 2024

Please improve the switchToIFrame method with frame/iframe switching support by an index. Currently, in the W3C-compliant mode, it doesn't work.

Please see minkphp/Mink#866 for more info.

I would happily create PR similar to minkphp/MinkSelenium2Driver#378 as well.

@uuf6429
Copy link
Member

uuf6429 commented Feb 22, 2024

Please improve the switchToIFrame method with frame/iframe switching support by an index. Currently, in the W3C-compliant mode, it doesn't work.

It should already work, and actually the PR you linked to looks broken - it only handles index (id), or?

    public function switchToIFrame($name = null)
    {
        $this->getWebDriverSession()->frame(array('id' => $name));
    }

vs

    public function switchToIFrame(?string $name = null): void
    {
        $frameQuery = $name;
        if ($name && $this->getWebDriver()->isW3cCompliant()) {
            try {
                $frameQuery = $this->getWebDriver()->findElement(WebDriverBy::id($name));
            } catch (NoSuchElementException $e) {
                $frameQuery = $this->getWebDriver()->findElement(WebDriverBy::name($name));
            }
        }

        $this->getWebDriver()->switchTo()->frame($frameQuery);
    }

I'd be fine with replacing ?string type-def with null|string|int PHPDoc type-hint though (just removing the type declaration is a step backword IMO).

@uuf6429
Copy link
Member

uuf6429 commented Feb 22, 2024

Looking at the json-wire link you provided it mentions:

JSON Parameters:
id - {string|number|null|WebElement JSON Object} Identifier for the frame to change focus to.

It doesn't say anything about an index just "identifier", however it also mentions the number type, so if I understand correctly, this means:

->switchToIFrame('xx');    // non-W3C mode / "old" mink logic, <iframe name=xx>
->switchToIFrame('xx');    // W3C mode, <iframe id=xx>
->switchToIFrame(1);       // W3C mode, first <iframe> element <- this is broken case we're discussing now, right?

@aik099
Copy link
Member Author

aik099 commented Feb 22, 2024

@uuf6429 , I've confirmed (by running a live test), that providing a number does switch to a window.frames[that_number] frame.

I'm only concerned by the frame switching by index, because in Selenium 3 using MinkSelenium2Driver frame switching by name doesn't work at all.

@uuf6429
Copy link
Member

uuf6429 commented Feb 22, 2024

I'm only concerned by the frame switching by index, because in Selenium 3 using MinkSelenium2Driver frame switching by name doesn't work at all.

I guess that's because MinkSelenium2Driver is only using id()? This driver actually does check selenium 3, and it works. For me this looks like a new feature; to support switching by index (which is also ok).

@aik099
Copy link
Member Author

aik099 commented Feb 22, 2024

Long story short: I've managed to get it working by writing a code equivalent to the one used by this driver:

  1. find web element by id/name
  2. try switching a frame to the web element instead of providing id/name directly

Thank you for the idea.

PR: minkphp/MinkSelenium2Driver#382 .

@aik099 aik099 closed this as completed Mar 4, 2024
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

Successfully merging a pull request may close this issue.

2 participants