protractor icon indicating copy to clipboard operation
protractor copied to clipboard

findElement can't find the right element.

Open Douwe92 opened this issue 13 years ago • 32 comments

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.

screenshot from 2013-09-19 09 49 28

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.

Douwe92 avatar Sep 19 '13 07:09 Douwe92

Does finding the element work OK? How does it not work - do you have an error message? Can you see the actions being performed?

juliemr avatar Sep 19 '13 23:09 juliemr

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

Douwe92 avatar Sep 20 '13 06:09 Douwe92

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?

scarletsky avatar Sep 22 '13 06:09 scarletsky

Tried everything I just can't get further !!

Douwe92 avatar Sep 24 '13 06:09 Douwe92

@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 avatar Sep 24 '13 20:09 stickel

@stickel No matter what I expect, it will throw this error. Like expect(thing.id).toBe(12345), it will still throw it

scarletsky avatar Sep 25 '13 01:09 scarletsky

@scarletsky check out the first question in the FAQ. Is that your problem?

juliemr avatar Sep 25 '13 01:09 juliemr

@juliemr yep Did it mean that if I need to test $http, I should set ptor.ignoreSynchronization ?

scarletsky avatar Sep 25 '13 02:09 scarletsky

@scarletsky Only if your application continuously polls $http.

juliemr avatar Sep 25 '13 03:09 juliemr

@stickel That's what I said. I literally tried everything... Cannot find any element on that page.

Douwe92 avatar Sep 25 '13 07:09 Douwe92

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);

Douwe92 avatar Sep 30 '13 13:09 Douwe92

Could it be Jquery Mobile changes alot to the DOM?

Douwe92 avatar Oct 02 '13 08:10 Douwe92

@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?

juliemr avatar Oct 02 '13 16:10 juliemr

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">&nbsp;</div>
        <div class="grid_8" style="text-align:center"><h2>{{"Data Loading" | _}}</h2></div>
        <div class="grid_2">&nbsp;</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">&nbsp;</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.

Douwe92 avatar Oct 03 '13 06:10 Douwe92

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'?

juliemr avatar Oct 04 '13 18:10 juliemr

Uhm there's something I would like to clarify here, I'm quite confused:

  1. 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 like expect(element.getValue()).then(function(value){ expect(value).toBe(something) } right?
  2. @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...
  3. @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!
  4. @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 avatar Oct 05 '13 04:10 wakandan

@wakandan

  1. Yes, that would work. That's because expect gets 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');
  1. You're correct. (What did I say to make you doubt that?)

juliemr avatar Oct 05 '13 04:10 juliemr

  1. @juliemr oh that's nice, I wasn't sure about that
  2. 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. ok doesn't look like a model, so he probably misunderstood that By.input selector.

wakandan avatar Oct 05 '13 14:10 wakandan

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:

  1. 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

Douwe92 avatar Oct 07 '13 07:10 Douwe92

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.

wakandan avatar Oct 07 '13 12:10 wakandan