7

I have problem with writing Selenium test to check my application. What I want to test is when user types correct login/password, correct page is shown and user is logged in.

The main issue is that my login form is generated as a AngularJS directive (I have two different login pages and this directive is reused in both places) and Selenium seems to be unable to see elements from this directive-generated markup. What is most important, tests were passing on this page before I've replaced regular markup with generated by directive.

So it looks like somehow Selenium is not able to see html elements that are generated by directive.

Any suggestion how I could overcome this issue? Except of course reverting this change introducing directive :)

Tomasz Dziurko
  • 1,668
  • 2
  • 17
  • 21
  • I am having the exact same issue. I have an angular website that I'm trying to test but when I run the junit tests, the element is not found. I tried various element locators. None worked. – Automationtested Nov 17 '15 at 02:18

3 Answers3

2

Ok, it looks like it was me misusing Geb with Selenium. I didn't specify default driver and Geb picked one not working with AngularJS. After I manually changed driver to Chrome, everything started to work.

Tomasz Dziurko
  • 1,668
  • 2
  • 17
  • 21
1

The page source will show the template before it has been compiled by Angular. You should be able to see the compiled template using Chrome's developer console: try right clicking on an element and selecting 'inspect element' to open it up.

driver.getPageSource() will fail for the same reason (it gets the uncompiled template), but driver.findElement() should work just fine.

<input id="username" type="text" ng-model="foo"/>

Should be found using

driver.findElement(By.id("username"));
Jmr
  • 12,078
  • 4
  • 39
  • 33
  • Unfortunately that's not the case. I've edited question to be more clear. The problem is that my tests were passing on this page before I've added this directive-generated markup. – Tomasz Dziurko Apr 30 '13 at 06:14
1

I don't think this is angular related but rather Selenium related, Selenium will only have the initial DOM before any JavaScript manipulation of it.

We have seen the same issue with simple jQuery plugins that rendered DOM elements.

See if the advice here helps:

Why can't Selenium find dynamically added DOM elements? Capybara doesn't recognize dynamically added DOM elements?

Community
  • 1
  • 1
Jens
  • 3,353
  • 1
  • 23
  • 27