Iam new to protractor, Please help me to find the element locator using below code in Protractor/angularJS i have tried using xpath and CSS. what locator can be used from this code
<button type="submit" value="autofocus" class="btn" data-ng-click="reset()">Reset</button>
Iam new to protractor, Please help me to find the element locator using below code in Protractor/angularJS i have tried using xpath and CSS. what locator can be used from this code
<button type="submit" value="autofocus" class="btn" data-ng-click="reset()">Reset</button>
Share
Improve this question
edited Feb 4, 2016 at 9:41
giri-sh
6,9622 gold badges27 silver badges50 bronze badges
asked Sep 30, 2015 at 6:54
LokeshLokesh
2142 silver badges11 bronze badges
2
-
Try this:
element(by.css('.btn'))
– Niezborala Commented Sep 30, 2015 at 7:02 - thanks for time but the thing is element(by.cssContainingText('.btn', 'Reset')); worked. ur code didnt show be error but it didnt even click the element. – Lokesh Commented Sep 30, 2015 at 7:23
4 Answers
Reset to default 5Here are various methods you can use apart from xpath and css. Locators specific to Protractor -
Get element using
buttonText
.element(by.buttonText('Reset'));
You can also add a custom locator for your button using
addLocator
in protractor. Here's an example of it.Use
cssContainingText
to get the element using both css and text properties.element(by.cssContainingText('.btn', 'Reset'));
If at all you have a longer text in your button element(for ex, "Reset This Value"), then use
partialButtonText
to get it.element(by.partialButtonText('Value'));
You can also use a shortcut to find elements using css.
$('.btn'); // = element(by.css('.btn'))
More details of the locators in Protractor are here.
You can use various General locators too -
Use
className
to get the element -element(by.className('btn'));
Use tagName to get the element if its the only button element on the page, which is a rare case -
element(by.tagName('button'));
Hope it helps.
element(by.cssContainingText('.btn', 'Reset'));
Above answer worked out.
try the following:
element(by.className("btn"));
or
$('.btn');
or
element(by.css("btn"));
it is better to use elementor (elementor URL) for protractor to find element locator. this will help u in finding the exact locator without any issues. but little bit time consuming. but u dont need to worry on the elements found.
elementor URL in mand prompt after starting the protractor.