我需要从菜单下拉菜单中检查注销。当我尝试查找元素时,出现错误无法找到元素。
我认为存在同步问题,因为当我添加browser.sleep(5000);时,测试通过了,但问题是它不稳定。
//from homePage.po.ts
static logOut() {
const EC = protractor.ExpectedConditions;
browser.waitForAngular();
const loader = element(by.className('loader-modal-container'));
browser.wait(EC.invisibilityOf(loader), 10001);
browser.waitForAngular();
browser.driver.findElement((by.id('user-drop-down'))).click();
(browser.driver.findElement(by.id('log-out'))).click();
browser.waitForAngular();
}
```
//login.e2e-spec.ts
import {LoginPage} from "../pages/login.po";
import {HomePage} from "../pages/homePage.po";
import {browser } from 'protractor';
describe('login page tests', () => {
beforeEach(function() {
LoginPage.navigateTo();
});
it('successful logout', () => {
LoginPage.logIn();
HomePage.logOut();
expect(browser.driver.getCurrentUrl()).toMatch(LoginPage.loginPageUrl);
});
});
````
//component.html
<div class="top-bar-menu">
<div class="top-bar-menu-item" id="user-drop-down"(click)="op1.show($event,opshow)" >
<div class="user-dropdown" #opshow >
<span id="user-dot" class="top-bar-dot dot semi-bold">{{given_name.substring(0,1).toUpperCase()}}{{family_name.substring(0,1).toUpperCase() }}</span>
{{ given_name+' '+family_name }}
</div>
</div>
NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="user-drop-down"]"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.16299 x86_64)
答案 0 :(得分:0)
尝试这样。.注销按钮上的Javascript执行器...
browser.driver.findElement((by.id('user-drop-down'))).click();
browser.waitForAngular();
browser.executeScript("document.getElementById('log-out').click()");
browser.waitForAngular();
答案 1 :(得分:0)
NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="user-drop-down"]"}
**(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.46.628402** (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT
10.0.16299 x86_64)
我怀疑驱动程序版本和chrome版本不兼容可能是导致您出现问题的原因。由于Chrome驱动程序2.46支持v71-73,因此您正在使用v74。我们还观察到有很多明显的例子。我建议在运行任何测试用例之前先确保驱动器和chrome浏览器兼容。