GithubHelp home page GithubHelp logo

Comments (15)

devinfd avatar devinfd commented on May 3, 2024 12

fyi; as a work around I have been use the script method to set the date. It's annoying but it works.

$this->browse(function ($browser) use ($user) {
    $browser->loginAs($user)
        ->visit('/sompage')
        ->script([
            "document.querySelector('#the_date_field').value = '2017-02-23'",
        ]);

    $browser->{do other stuff}
});

One thing to keep in mind is that script does not return the $browser instance so it needs to be terminated and the browser variable recalled.

from dusk.

dorellango avatar dorellango commented on May 3, 2024 4

Another solution is use the keys() method

keys('.selector', 'datetotype');

Laravel Dusk Doc.

from dusk.

thijsvdanker avatar thijsvdanker commented on May 3, 2024 1

It looks like this issue has been around for at least 3 years:
http://stackoverflow.com/questions/15360362/clear-date-input-fails-on-chromewebdriver

I've created a PR (#125) to allow typing into a field without clearing it, but I'm not sure if that's the way to go.

from dusk.

driesvints avatar driesvints commented on May 3, 2024 1

Just found out there's already a method for this: append.

from dusk.

georaldc avatar georaldc commented on May 3, 2024

Tested this just now and it works for me, but my setup works through selenium and firefox. I could never get chromedriver to work on centos 6

from dusk.

leewillis77 avatar leewillis77 commented on May 3, 2024

Hmm, maybe just a ChromeDriver issue then? If someone can confirm then happy to report this elsewhere?

from dusk.

devinfd avatar devinfd commented on May 3, 2024

@devdorego I tried use the keys method but every time it would misconfigure the date. Maybe you found a reliable way?

->keys('#date', '2017-03-01')

from dusk.

leewillis77 avatar leewillis77 commented on May 3, 2024

@devinfd If you look at my original report I gave an example of how keys() can be used as a workaround.

from dusk.

devinfd avatar devinfd commented on May 3, 2024

Follow up, I just end up creating a macro for this:

use Laravel\Dusk\Browser;

Browser::macro('typeDate', function ($selector, $year, $month, $day) {
    $this->keys($selector, $day)
        ->keys($selector, $month)
        ->keys($selector, $year);

        return $this;
});

$this->browse(function ($browser) use ($user) {
    $browser->loginAs($user)
        ->visit("/somepage")
       ->typeDate('#some_date', '2017', '04', '11');
});

The problem with this is that its depended on the users system date format. Ie: the date may not be displayed in day/month/year format.

from dusk.

Zhythero avatar Zhythero commented on May 3, 2024

@devinfd
Replace

->keys('#date', '2017-03-01')

with

->keys('#date', '20170301') // omit the dashes

from dusk.

devinfd avatar devinfd commented on May 3, 2024

from dusk.

driesvints avatar driesvints commented on May 3, 2024

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.

from dusk.

driesvints avatar driesvints commented on May 3, 2024

Hmm I can actually reproduce this. Unfortunately since this is related to the ChromiumDriver it's not really a Dusk issue. I can however re-send a the PR that was closed but with a different method. I'll try to do that soonish but feel free to send one in before me.

from dusk.

devinfd avatar devinfd commented on May 3, 2024

I ultimately resolved this by not using an input[type="date"] field. Partly because of this issue but also my users were complain about the browser venders date UI.

from dusk.

amiranagram avatar amiranagram commented on May 3, 2024

This worked perfectly fine for me with Chromium driver:

use Carbon\CarbonInterface;
use Facebook\WebDriver\WebDriverKeys;
use Illuminate\Support\Carbon;
use Laravel\Dusk\Browser;

Browser::macro('inputDate', function ($selector, $date) {
    $date = $date instanceof CarbonInterface ? $date : Carbon::parse($date);

    $this->resolver->findOrFail($selector)
        ->sendKeys([
            $date->format('d'),
            $date->format('M'),
            WebDriverKeys::TAB,
            $date->format('Y'),
        ]);

    return $this;
});
$browser
    ->inputDate('@date', $tomorrow = now()->addDay())
    ->assertInputValue('@date', $tomorrow->format('Y-m-d'))

from dusk.

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.