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

Allow usage of XPathSelector in Page::waitForElement #539

Open
jhoopmann opened this issue Aug 16, 2023 · 3 comments · Fixed by #544
Open

Allow usage of XPathSelector in Page::waitForElement #539

jhoopmann opened this issue Aug 16, 2023 · 3 comments · Fixed by #544
Labels

Comments

@jhoopmann
Copy link
Contributor

jhoopmann commented Aug 16, 2023

$element = Utils::getElementPositionFromPage($this, new CssSelector($selectors), $position);

#531 (comment)

It's always using CssSelector.

It should be possible to pass an instance of a custom selector.


   /**
     * Wait until page contains Node.
     *
     * @param string|Selector $selectors
     * @param int $timeout = 30000
     * @throws Exception\OperationTimedOut
     */
    public function waitUntilContainsElement($selectors, int $timeout = 30000): self
    {
        $this->assertNotClosed();

        Utils::tryWithTimeout($timeout * 1000, $this->waitForElement($selectors));

        return $this;
    }

    /**
     * @param string|Selector $selectors
     * @param int $position = 1
     * @return bool|\Generator
     *
     * @internal
     */
    public function waitForElement($selectors, int $position = 1)
    {
        if (!($selectors instanceof Selector)) {
            $selectors = new CssSelector($selectors);
        }

        $delay = 500;
        $element = [];

        while (true) {
            try {
                $element = Utils::getElementPositionFromPage($this, $selectors, $position);
            } catch (JavascriptException $exception) {
                yield $delay;
            }

            if (\array_key_exists('x', $element)) {
                return true;
            }

            yield $delay;
        }
    }
@enricodias
Copy link
Member

The code looks good. Can you open a PR with this change?
We also need to update the docs and add a test for that feature.

@jhoopmann
Copy link
Contributor Author

The code looks good. Can you open a PR with this change? We also need to update the docs and add a test for that feature.

Apologies for the delayed response. I've opened a pull request and hope the changes are okay so far.

@enricodias enricodias linked a pull request Sep 7, 2023 that will close this issue
Copy link

stale bot commented Mar 13, 2024

This issue has been automatically marked as stale because there has been no recent activity. It will be closed after 30 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants