ng-click using selenium webdriver

11,582 views
Skip to first unread message

Mahender Tirumala

unread,
Mar 6, 2015, 11:33:30 PM3/6/15
to seleniu...@googlegroups.com
hi,

iam automating angular js application, i am stuck up with clickin a button,iam unable to click using input-id, and other option is it has ngclick ,can u please share java script code??? for ng click

thanks
Mahender

Krishnan Mahadevan

unread,
Mar 6, 2015, 11:36:32 PM3/6/15
to seleniu...@googlegroups.com
You would need to show us the html snippet of the page that you are trying to work with.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/984773ec-e325-4177-a9fc-4f2693935676%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shawn Knight

unread,
Mar 8, 2015, 10:58:35 PM3/8/15
to seleniu...@googlegroups.com
Can you share your code, your HTML code, your version of selenium and the browser version?

Mahender Tirumala

unread,
Mar 9, 2015, 2:24:09 AM3/9/15
to seleniu...@googlegroups.com
 please find attached screens hot
Capture.PNG

Shawn Knight

unread,
Mar 9, 2015, 10:41:39 AM3/9/15
to seleniu...@googlegroups.com
using css, this should work --> button[ng-click *= 'sendForApproval']


On Friday, March 6, 2015 at 10:33:30 PM UTC-6, Mahender Tirumala wrote:

Mahender Tirumala

unread,
Mar 10, 2015, 12:27:12 AM3/10/15
to seleniu...@googlegroups.com
we dont have ngclick property in webdriver rite?

we have only by.id,by.name, by.xpath

David

unread,
Mar 10, 2015, 9:41:59 PM3/10/15
to seleniu...@googlegroups.com
What Shawn mentioned is By.cssSelector, which is supported. You incorporate the ng-click property as part of the CSS selector value.

Alternatively, you could do it in XPath too: 

//button[contains(@ng-click,'sendForApproval')]

or for absolute match and not partial property value match

//button[@ng-click='sendForApproval']

Mahi Tirumala

unread,
Mar 12, 2015, 7:26:01 AM3/12/15
to seleniu...@googlegroups.com
thank you david,shawn, for ng-binding and ngrepeater also can we use in same way, also i heard we should use protractor/webdriver i.o for angular js applications, can we use selenium webdriver for angular applications?

PeterJeffreyGale

unread,
Mar 12, 2015, 7:38:42 AM3/12/15
to seleniu...@googlegroups.com
Yes, raw webdriver works well for angular without needing protractor or even ngWebDriver

Shawn Knight

unread,
Mar 12, 2015, 7:53:25 AM3/12/15
to seleniu...@googlegroups.com
As PeterJeffreyGale has indicated, it can be done with straight webdriver. I would point out --  using the angular attributes could cause you issues down the road if the application changes the underlining JS framework or the angular attribute becomes deprecated -- In my application, I am moving away from angular attributes and start using HTML 5 "data-" attributes for testing hooks.

PeterJeffreyGale

unread,
Mar 12, 2015, 7:59:39 AM3/12/15
to seleniu...@googlegroups.com
Personally, I try to write Xpath expressions which reflect as closely as possible only what the user sees on the screen, only rarely resorting to using attributes that the user cannot see unless they dip into the page source.

The tests will only usually fail then if the UI has changed somehow, either by design or because of a defect, which is ideally when you would want it to fail, and not continue working despite the change.

David

unread,
Mar 12, 2015, 3:40:15 PM3/12/15
to seleniu...@googlegroups.com
@PeterJeffreyGale, you bring up a good topic. 

I try to follow that too. In terms of text related elements, that often or sometimes gets associated to matching by element/node text that a user sees on the screen. And when paired with parent/child/sibling/etc. XPath relationships can be used to match/reference other elements relative to the text (e.g. you have a group of elements that define a feature - the checkbox or radio button, the text label we key off of as the  relative root, the click handler (if not the checkbox/radio button itself, etc.)

Unfortunately, taking this approach deviates from going with CSS selectors, which are often (or used to be) faster than XPath, because CSS doesn't offer element/node text matching. So I end up using XPath often just because I want to take that approach, where I know the visual text change is easier to track & verify than changes in the underlying attributes (class, ID, etc. particularly for elements sem-auto-generated by popular javascript libraries).

Is what I describe what you aim for as well?

Seshu Kumboju

unread,
Jan 8, 2019, 4:49:00 AM1/8/19
to Selenium Users

//button[@ng-click='sendForApproval']  didn't worked for me , any other solution ?

Serguei Kouzmine

unread,
Jan 11, 2019, 10:44:14 AM1/11/19
to Selenium Users
@Seshu Kumboju  first there is a number of java ports of the protractor that ws originally invented per angularjs

e.g. Paul's  or mine


These offer addiional loctor 'By's  which reflect the way MVC way was built in Angular

IIRC it does not cover specificlly ng-click but model,   repeater, binding , options  buttontext csswithtextinside etc.
Second you  should be able to getaway with pure core Seleniu By's (cssSelector or xpath)  - please continue 
 debug yor selector to find why.

Please post the AS-TEXT frgment of the confusin page not screen shot 
if you still need help,

Thanks 
Reply all
Reply to author
Forward
0 new messages