isElementPresent 的简单量角器测试因不支持的定位器策略而失败 [英] Simple protractor test for isElementPresent failing with unsupported locator strategy

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

问题描述

我的测试:

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

但这会出错:

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

奇怪的是,它指向的是 isElementPresent 行,而不是点击的那一行.我对 webdriver 很陌生,如果我错过了一些明显的东西,我深表歉意.我正在使用 mocha 框架(这意味着量角器的金丝雀版本)运行,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.

任何想法表示赞赏.

推荐答案

$('#logout') 是一个 WebElement.isElementPresent 采用定位器,例如 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();

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

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