0

I'm not able to enter text into a specific input box as determined by a data attribute. There could be dozens of inputs with the same class, so I'd prefer not to add dusk='xxxx' all over the page.

For route and server-side efficiency, the AJAX function pulls a type from the array of inputs and routes to a function that branches the action.

Blade code:

{!! Form::text('question[]', null, 
         ['class'=>'form-control actionChange', "data-id"=>$question->id, "data-type"=>'question']) !!}

The page starts with other questions with a different type, so I have tried using nth-child(x) to grab the selector within the modal, but no success. I've tried using $browser->script() as well.

Reading several similar questions, such as this one, it appears that a loop within the modal is likely the best way to go. This method correctly assigns the selector to the loop variable, $input. It correctly clear()s data, and I've tested similar code with click() and it successfully works. However, it will not enter data in the input. type() and keys() don't appear to work with the RemoteWebElement, so I believe my only choice to enter data is sendKeys().

Dusk test code:

$browser->assertPathIs('/notice')
        ->whenAvailable('.modal', function($modal) use($browser) {
           $modal->assertSee('Survey for:')
             ->waitFor('#heading')
             // WORKS fine
             ->keys('#heading', 'Edited Heading for Survey', '{enter}')
             ->waitFor('.actionSurvey');

                // Edit a question -- NOT WORKING
                foreach ($browser->elements('.actionChange') as $input) {
                    $dataType = $input->getAttribute('data-type');
                    if($dataType === 'question') {
                        $input->clear()  // WORKS Fine 
                            ->sendKeys('Edited_Question') // NOT successful
                        break;

I've tried with and without the clear() method, as well as various selector choices both within and out of the modal loop. Same for script() Also, tried using the $modal variable to get the elements, but this was just a guess as I'm a bit out of my depth of understanding at this point.

I probably fubar'd something basic, but I don't understand why one method works, and another doesn't on the same handle.

Watercayman
  • 7,970
  • 10
  • 31
  • 49
  • @Watercaymen Did you tried finding the element directly using the underlying driver $browser->driver->findElement(WebDriverBy::cssSelector('input[data-id="3"]')) ? – Tushar Dec 09 '19 at 03:14
  • @Tushar: thank you very much for your response. You code correctly finds the element, like the loop above does (though yours is more efficient). However, I get the **same result** - it can clear the input, but it will not send keys to the modal input. – Watercayman Dec 09 '19 at 14:33
  • @Watercaymen Hard to debug this without actually looking at the screen you are working on. One way to debug this would be to put $browser->tinker() just after the clear() method. And then you can try out different methods in the terminal of what is working and what isn't. – Tushar Dec 10 '19 at 02:59
  • @Tushar. WOW! That is absolutely brilliant. I didn't realise you could do this, but it is extremely helpful. Thank you very much. I have been able to use tinker using your code, but I'm getting the same results. I am starting to think this may be an issue with dusk/selenium, as I can `clear()`, but nothing is allowing keys to be sent on the modal, even though the handle is correct. – Watercayman Dec 11 '19 at 01:34
  • Try upgrading the chrome-driver version if you are not on latest. I once had this crazy issue with driver not switching to iFrame and upgrading the chrome-driver fixed that. – Tushar Dec 11 '19 at 05:42

0 Answers0