Git Product home page Git Product logo

Comments (7)

kbond avatar kbond commented on July 30, 2024 1

I'm going to close as this seems like a niche feature that can be achieved with a custom browser or component. If there is future interest in this we can revisit.

from browser.

benr77 avatar benr77 commented on July 30, 2024

Update to the above - this actually has uncovered a wider application. I am trying to simulate submitting a form with a form collection, and the JS to add collection items is unavailable.

Using e.g. Codeception I am able to simply specify what the form fields would be if I had added several items to the collection, and then submit these.

This is the same case as above for the select with autocomplete - instead of wanting to fill in form fields directly, we need a general way to manipulate the form data that is send when the form submit click is simulated.

from browser.

benr77 avatar benr77 commented on July 30, 2024

I have a working solution for the autocomplete field which is not very elegant but seems to work.

->use(function(AbstractBrowser $browser, Crawler $crawler)
    {
        $form = $crawler->selectButton('Next Step')->form();
        $form['customer']->disableValidation()->select('1234');
        $browser->submit($form);
    })

I don't think the callback function(AbstractBrowser $browser, Crawler $crawler) is documented but it works.

from browser.

kbond avatar kbond commented on July 30, 2024

Interesting solution. You could probably wrap that up into a dynamic custom browser method.

from browser.

benr77 avatar benr77 commented on July 30, 2024

I've done exactly that.

// AppBrowser

public function selectAutocompleteField(string $formButtonName, string $selector, string $value): self
{
    return $this->use(function(AbstractBrowser $browser, Crawler $crawler) use ($formButtonName, $selector, $value)
    {
        $form = $crawler->selectButton($formButtonName)->form();
        $form[$selector]->disableValidation()->select($value);
        $browser->submit($form);
    });
}

It would be good if I didn't need to pass the form name...

from browser.

kbond avatar kbond commented on July 30, 2024

What about:

public function selectAutocompleteField(string $selector, string $value): self
{
    return $this->use(function(AbstractBrowser $browser, Crawler $crawler) use ($formButtonName, $selector, $value)
    {
        $form = $crawler->filter(\sprintf('[name="%s"]', $selector))->ancestors()->filter('form')->form();
        $form[$selector]->disableValidation()->select($value);
        $browser->submit($form);
    });
}

from browser.

benr77 avatar benr77 commented on July 30, 2024

Yep - that's a great improvement thanks!

from browser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.