为isElement present简单量角器测试与不支持的定位战略失败 [英] Simple protractor test for isElementPresent failing with unsupported locator strategy

查看:473
本文介绍了为isElement present简单量角器测试与不支持的定位战略失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试:

it('should allow login', function() {
  browser.get('index.html');

  $('#username').sendKeys('administrator');
  $('#password').sendKeys('password');
  $('#login').click();

  var logout = $('#logout');
  expect($p.isElementPresent(logout)).to.eventually.be.true;
}); 

但这个错误跟出来:

But this errors out with:

Error: Unsupported locator strategy: click
  at Error (<anonymous>)
  at Function.webdriver.Locator.createFromObj (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/locators.js:97:9)
  at Function.webdriver.Locator.checkLocator (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/locators.js:111:33)
  at webdriver.WebDriver.findElements (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:805:31)
  at webdriver.WebDriver.isElementPresent (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:787:29)
  at Protractor.isElementPresent (/usr/local/lib/node_modules/protractor/lib/protractor.js:476:22)
  at /Users/pschuegr/wt/client/e2e/login_test.js:26:15

奇怪的是,它指向isElement present线,而不是与点击就行了。我是pretty新webdriver的,所以道歉,如果我错过了一些东西明显。我使用的是摩卡框架(这意味着量角器金丝雀版),FWIW运行。

Strangely, it points to the isElementPresent line, rather than the line with the click. I'm pretty new to webdriver, so apologies if I missed something obvious. I'm running using the mocha framework (which means the canary version of protractor), fwiw.

任何想法AP preciated。

Any ideas appreciated.

推荐答案

$('#注销')是一个WebElement。 isElement present 需要一个定位,如by.css

$('#logout') is a WebElement. isElementPresent takes a locator, like by.css

$('#username').sendKeys('administrator');
$('#password').sendKeys('password');
$('#login').click();

var logout = by.css('#logout');
browser.wait(function() { return $p.isElementPresent(logout); }, 8000);
expect($p.isElementPresent(logout)).toBeTruthy();

这篇关于为isElement present简单量角器测试与不支持的定位战略失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆