量角器在定位元素时不一致。如何解决定位器问题
Protractor is inconsistent in locating elements. How to resolve the locator issue
量角器新手和 运行 问题。任何帮助是极大的赞赏!
1.量角器有时定位元素有时不起作用
public async clickForgetPasswordLink() {
let expectedValue = "Forgot Password";
let link = await element(by.linkText('Forgot Password?'));
await browser.wait(until.visibilityOf(link),
TIMEOUT_MILLIS, 'Unable to locate forgot password link...').then(()=>{
link.click();
})
// await link.click();
let emailText = link.getAttribute("aria-label");
await emailText.then((text) => {
logger.info("Getting forgot password link value:" + text);
expect(text).toEqual(expectedValue);
browser.driver.sleep(2000);
});
}
2。我无法找出 StaleElementError 问题的根本原因。在第二个套件中,我正在复制粘贴相同的代码,但错误仅针对第二个套件而不是第一个套件
stale element
表示量角器看到元素。所以它确实找到了它。
当您尝试 await
对多个元素 (20+) 执行操作时,就会出现陈旧元素,例如 await element.all().getText()
因此请找到执行此操作的位置并找出解决方法。
您的代码片段中的代码本来可以更具可读性
public async clickForgetPasswordLink() {
let expectedValue = "Forgot Password";
let link = element(by.linkText('Forgot Password?'));
await browser.wait(
until.visibilityOf(link),
TIMEOUT_MILLIS,
'Unable to locate forgot password link...'
);
await link.click();
let emailText = await link.getAttribute("aria-label");
logger.info("Getting forgot password link value:" + emailText);
expect(emailText).toEqual(expectedValue);
await browser.driver.sleep(2000);
}
public async clickForgetPasswordLink() {
let expectedValue = "Forgot Password";
try {
let link = await element(by.linkText('Forgot Password?'));
await browser.wait(await until.elementToBeClickable(link),
TIMEOUT_MILLIS, 'Unable to locate forgot password link...').then(()=>{
browser.driver.sleep(2000);
});
await link.getAttribute("aria-label").then((text) => {
logger.info("Getting forgot password link value:" + text);
expect(text).toEqual(expectedValue);
});
await link.click();
browser.driver.sleep(2000);
}catch (e) {logger.error("Exception error caught" + e); }
}
public async clickForgetPasswordLink() {
let expectedValue = "Forgot Password";
let link = await element(by.linkText('Forgot Password?'));
await browser.wait(until.visibilityOf(link),
TIMEOUT_MILLIS, 'Unable to locate forgot password link...').then(()=>{
link.click();
})
// await link.click();
let emailText = link.getAttribute("aria-label");
await emailText.then((text) => {
logger.info("Getting forgot password link value:" + text);
expect(text).toEqual(expectedValue);
browser.driver.sleep(2000);
});
}
2。我无法找出 StaleElementError 问题的根本原因。在第二个套件中,我正在复制粘贴相同的代码,但错误仅针对第二个套件而不是第一个套件
stale element
表示量角器看到元素。所以它确实找到了它。
当您尝试 await
对多个元素 (20+) 执行操作时,就会出现陈旧元素,例如 await element.all().getText()
因此请找到执行此操作的位置并找出解决方法。
您的代码片段中的代码本来可以更具可读性
public async clickForgetPasswordLink() {
let expectedValue = "Forgot Password";
let link = element(by.linkText('Forgot Password?'));
await browser.wait(
until.visibilityOf(link),
TIMEOUT_MILLIS,
'Unable to locate forgot password link...'
);
await link.click();
let emailText = await link.getAttribute("aria-label");
logger.info("Getting forgot password link value:" + emailText);
expect(emailText).toEqual(expectedValue);
await browser.driver.sleep(2000);
}
public async clickForgetPasswordLink() {
let expectedValue = "Forgot Password";
try {
let link = await element(by.linkText('Forgot Password?'));
await browser.wait(await until.elementToBeClickable(link),
TIMEOUT_MILLIS, 'Unable to locate forgot password link...').then(()=>{
browser.driver.sleep(2000);
});
await link.getAttribute("aria-label").then((text) => {
logger.info("Getting forgot password link value:" + text);
expect(text).toEqual(expectedValue);
});
await link.click();
browser.driver.sleep(2000);
}catch (e) {logger.error("Exception error caught" + e); }
}