1

I would like to click in angularjs using casperjs. However, i cant achieve this. The webpage populates a dialogbox everytime i run so this is why i need to click.

This is what i try to click

<button class="ng-scope" trans="" ng-click="closeDialog(activeDialog, 'okButton');$event.stopPropagation();" ng-if="!activeDialog.yesno">Tamam</button>

This is what i use in casperjs

casper.then(function () {
this.evaluate(function() {  

    $($(document).find('button[ng-if="!activeDialog.yesno"]')).click();
});

this.wait(3000);

Thanks in advance

3 Answers 3

1

I solved this problem by using the code below:

casper.waitUntilVisible('.close-j',function(){
   this.click(x("//a[@ng-show='!activeDialog.hideCloseButton']"‌​));
   this.wait(5000);
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can solve it this way also:

this.click('button[ng-if="!activeDialog.yesno"]');

I had similar problem. Every time I login to the website a popup window opens and I have to put certain value text field and click button. That's how popup window class and other attributes looks like:

<button class="md-raised md-primary md-button md-button md-ink-ripple" aria-label="Okey", type="button">

That's how I solved it:

this.waitUntilVisible('button[aria-label="Okay"]', function () {
    this.click('button[aria-label="Okay"]');
    this.echo("########### Okay button clicked")
})

Comments

0

Don't use the attribute value in the selector. You can either give your button a unique class or id to select it:

<button class="yesno" trans="" ng-click="closeDialog(activeDialog, 'okButton');$event.stopPropagation();" ng-if="!activeDialog.yesno">Tamam</button>

and

this.evaluate(function() {  

    $($(document).find('.yesno')).click();
});

or if there is only one button just use:

this.evaluate(function() {  

    $($(document).find('button[ng-if]')).click();
});

5 Comments

Thanks for your reply. But both of them did not work. I get this error when i try "Wait timeout of 5000ms expired, exiting. "
that is a different issue, you are probably calling that before angular finishes loading, so either try to increase the timeout or find a way to post pone your call until the loading is finished @Quicksilver
Hi, sorry for late answer. I solved this problem using codes below casper.waitUntilVisible('.close-j',function() { this.click(x("//a[@ng-show='!activeDialog.hideCloseButton']")); this.wait(5000); });
@Yaser What if the button doesn't have any unique class or id? I think it shouldn't be a problem if attribute value is used.
@johnshumon you're right but only if there is one button found by that query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.