FotisK
FotisK

Reputation: 1177

How to fill input field in div without id and name within CasperJS

I have the below page code, that has two input fields one for username and one for password:

enter image description here

In some other pages it seems very easy and with the below casperjs code I would be able to login:

...        
    test.assertExists('form[name="loginForm"]', "Login form is found");
    this.fill('form[name="loginForm"]', {
              'userId': 'admin',
              'password': 'admin'
    }, true);
...

But in this case the input fields don't have a name to use in the fill function!

From the page I can recognize that the form is called 'loginForm' but how do I fill the input fields without id and name?

The important thing is that I need to stay logged in after this step to continue with other test on the same page.

Upvotes: 1

Views: 812

Answers (1)

Artjom B.
Artjom B.

Reputation: 61892

You can use arbitrary CSS selectors with casper.fillSelectors() instead of casper.fill().

In your case that could be

this.fillSelectors('form[name="loginForm"]', {
    'input.eaLogin-loginUsername': 'admin1',
    'input.eaLogin-loginPassword': 'admin2'
}, true);

Upvotes: 1

Related Questions