findElement can't find the right element.
So basically, I am logging in my app. I get at a pincode screen where you have to input a number and click okay. basically the whole pincode thing I can't even get one button to be clicked. Not even send a 1 to the input and press ok.
I've tried everything.

That is my code. I could give you my test code but basically everything I tried just didn't work so.
ptor.findElement(protractor.By.input("ok")).click(); ptor.findElement(protractor.By.input("pincode")).sendKeys("1")
not working.
Does finding the element work OK? How does it not work - do you have an error message? Can you see the actions being performed?
Yeah so the login page works and it gets past that. But when I get at the pincode nothing happens and just times out, not even an error
The same issue. and here is my code.
controller:
$http.get(xxx).success(function (data) {
$scope.objects = data;
});
spec.js
it('should test', function () {
var thing = ptor.findElement(protractor.By.repeater('object in objects').row(1));
});
The terminal output:
Failures:
1) myModule should test
Message:
timeout: timed out after 15000 msec waiting for spec to complete
Stacktrace:
undefined
Finished in 19.03 seconds
1 test, 1 assertion, 1 failure
How can I fixed it?
Tried everything I just can't get further !!
@Douwe92 In the original question you have ptor.findElement(protractor.By.input("ok")). Changing By.input to By.id should work for the button.
@scarletsky It doesn't look like you're testing anything. If you put an expectation in should test what happens?
@stickel
No matter what I expect, it will throw this error.
Like expect(thing.id).toBe(12345), it will still throw it
@scarletsky check out the first question in the FAQ. Is that your problem?
@juliemr yep
Did it mean that if I need to test $http, I should set ptor.ignoreSynchronization ?
@scarletsky Only if your application continuously polls $http.
@stickel That's what I said. I literally tried everything... Cannot find any element on that page.
Still got his problem, Even on other pages I can't find something with the ID
<li id="about" ><a ngm-vclick="navigateToView('about.main')">{{"About" | _}}</a></li>
expect(ptor.isElementPresent(protractor.By.id("about"))).toBe(true);
Could it be Jquery Mobile changes alot to the DOM?
@Douwe92 I'm sure you didn't try literally everything :)
Can you give us:
- The relevant section of your template
- Your test code
- The error that is output?
ptor.findElement(protractor.By.input('username')).sendKeys('username');
ptor.findElement(protractor.By.input('password')).sendKeys('password');
ptor.findElement(protractor.By.id('login')).click();
ptor.sleep(2000);
ptor.findElement(protractor.By.input("pincode")).sendKeys("1");
ptor.findElement(protractor.By.input("ok")).click();
<section id="${id}" data-role="dialog" data-close-btn="none" data-theme="${theme}" ng:controller="${controller}" >
<div data-role="header" data-theme="b"><h2>{{"Pincode" | _}}</h2></div>
<div ng-hide="dataLoaded && settingsLoaded && cashiersLoaded" data-role="content" data-theme="a">
<div class="container_12">
<div class="grid_2"> </div>
<div class="grid_8" style="text-align:center"><h2>{{"Data Loading" | _}}</h2></div>
<div class="grid_2"> </div>
</div>
</div>
<div ng-show="dataLoaded && settingsLoaded && cashiersLoaded" data-role="content" data-theme="a">
<div class="container_12">
<div class="grid_8 pincode"><input type="password" id="pincode" ng-model="pincode" on-focus="focused=true" autofocus></div>
<div class="grid_4"><input id="ok" type="button" ngm-vclick="pinCodeHandler()" value=OK></div>
</div>
<div id="pinpad" class="container_12">
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('1')" value="1" id="1"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('2')" value="2" id="2"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('3')" value="3" id="3"></div>
</div>
<div id="pinpad" class="container_12">
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('4')" value="4" id="4"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('5')" value="5" id="5"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('6')" value="6" id="6"></div>
</div>
<div id="pinpad" class="container_12">
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('7')" value="7" id="7"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('8')" value="8" id="8"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('9')" value="9" id="9"></div>
</div>
<div id="pinpad" class="container_12">
<div class="grid_4"> </div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('0')" value="0" id="0"></div>
<div class="grid_4"><input class="btn" type="button" ngm-vclick="onKeyPress('C')" value="C" id="C"></div>
</div>
</div>
</section>
There is no error output, just a timeout.
What is the timeout message? Is the Jasmine spec timing out, or is the script timing out with the message: 'Timed out waiting for Protractor to synchronize'?
Uhm there's something I would like to clarify here, I'm quite confused:
expect(thing.id).toBe(12345): would this actually work? I remember if I want to get some "value" from an web element, I would need to do it something likeexpect(element.getValue()).then(function(value){ expect(value).toBe(something) }right?- @Douwe92 have you tried using xpath for your selectors? I thought it wasn't as rich as jquery selector but it turned out I was wrong, it is quite powerful. I wonder if that would work instead...
- @juliemr I thought this selector
ptor.findElement(protractor.By.input("ok")).click();is finding an input element which is associated with a model's name of "ok", something like<input ng-model="ok">is it not? If it's not the case then probably most of my tests were wrong! - @Douwe92 as @stickel said,
ptor.findElement(protractor.By.id("ok"))should have workd. I'm curious what could went wrong if that didn't.
@wakandan
- Yes, that would work. That's because
expectgets patched to understand promises. It is also perfectly valid to use the promise directly, which would look like:
element.getValue().then(function(val) {
expect(val).toEqual('something');
});
// is equivalent to
expect(element.getValue()).toEqual('something');
- You're correct. (What did I say to make you doubt that?)
- @juliemr oh that's nice, I wasn't sure about that
- I was just clarifying if my understanding is correct. I was confused because @Douwe92 was using
ptor.findElement(protractor.By.input("ok")).click();in his code.okdoesn't look like a model, so he probably misunderstood thatBy.inputselector.
I tried it with ID, exactly the same. It gets on the page after the login. and then it just does nothing, the browser doesn't close and my terminal gives this error:
- login should succesfully login to the backoffice Message: timeout: timed out after 20000 msec waiting for spec to complete Stacktrace: undefined
Finished in 27.505 seconds 1 test, 1 assertion, 1 failure
Stacktrace: undefined seems bad...
Have you tried debugging after ptor.findElement(protractor.By.input("ok")).click();?
For that, add ptor.debugger() after that line - where you clicked the button and wants to see what happens next, then run protractor debug <your_protractor_conf>. After it runs, press "c" (for continue) when it stops the first time. The next time it stops should be triggered by that debugger line you just put in. Then, take a look in the browser, fire up the console or something to find out what's happening...Hope it helps.