Angularjs 无法使用量角器在Angular JS应用程序中找到元素

Angularjs 无法使用量角器在Angular JS应用程序中找到元素,angularjs,selenium,protractor,Angularjs,Selenium,Protractor,我对Angular JS应用程序测试是个新手。我尝试过在线提供的示例Angular JS应用程序 链接: 在网络量角器中探索后是测试AngularJS的最佳方法。我已经尝试使用以下代码在上面的链接中查找元素。我尝试了所有可能的定位器,但无法捕获任何web元素 量角器版本:2.5.1 代码: 配置文件:: exports.config = { //The address of a running selenium server. seleniumAddress: 'http://loc

我对Angular JS应用程序测试是个新手。我尝试过在线提供的示例Angular JS应用程序

链接:

在网络量角器中探索后是测试AngularJS的最佳方法。我已经尝试使用以下代码在上面的链接中查找元素。我尝试了所有可能的定位器,但无法捕获任何web元素

量角器版本:2.5.1

代码:

配置文件::

exports.config = {
    //The address of a running selenium server.
  seleniumAddress: 'http://localhost:4444/wd/hub',
 //Here we specify the name of the specs files.
  specs: ['testspec.js']
}
错误:

 1) angularjs homepage should load the home page
   Message:
     NoSuchElementError: No element found using locator: By.xpath(".//*[@id=\"na
v\"]/li[2]/a")
   Stacktrace:
     NoSuchElementError: No element found using locator: By.xpath(".//*[@id=\"na
v\"]/li[2]/a")
    at new bot.Error (C:\Users\CP042756\AppData\Roaming\npm\node_modules\protrac
tor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
    at C:\Users\CP042756\AppData\Roaming\npm\node_modules\protractor\lib\element
.js:694:15
    at Array.forEach (native)
    at goog.async.run.processWorkQueue (C:\Users\CP042756\AppData\Roaming\npm\no
de_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:
15)
    at process._tickCallback (node.js:356:9)
Error

请提供帮助并感谢

在查找元素之前,所需元素位于
iframe
中:

browser.switchTo().frame("preview-frame"); 
element(by.xpath('.//*[@id="nav"]/li[2]/a')).click();
preview frame
iframe
的名称


您可能已经知道,AngularJS应用程序加载在此
iframe
-这可能就是您设置
ignoreSynchronization
标志的原因

我认为您可以测试您的应用程序,而无需关闭同步,也无需调整
ignoreSynchronization
标志-
data-ng-app
属性设置在
iframe
内的
body
上。如果直接转到加载
iframe
的URL,
量角器将自动检测AngularJS应用程序,并与之同步工作:

it('should load the home page', function() {
  browser.get('http://iarouse.com/dist-square/v2.0.1/index.html');
  browser.driver.manage().window().maximize();

  element(by.xpath('.//*[@id="nav"]/li[2]/a')).click();
});

您好,您的元素位于iframe内部,在您尝试单击此链接之前,您必须使用browser.switchTo().frame(“您的iframe的名称”)切换到iframe

有关

希望这有帮助

it('should load the home page', function() {
  browser.get('http://iarouse.com/dist-square/v2.0.1/index.html');
  browser.driver.manage().window().maximize();

  element(by.xpath('.//*[@id="nav"]/li[2]/a')).click();
});
browser.switchTo().frame("preview-frame"); 
element(by.xpath('.//*[@id="nav"]/li[2]/a')).click();