简体   繁体   English

我没有出现原生硒错误,例如``找不到元素''或``元素不可点击'',相反,我在量角器中收到超时错误

[英]I do not get native selenium error such as 'Element not Found' or 'Element is not clickable'.Instead i get timeout error in protractor

I'm working in Protractor cucumber framework.I do not get native selenium errors such as 'Element not Found' or 'No Such Element Found' or 'Element is not clickable' if the element is not found in page or not clickable.Instead i get "TimeoutError: Wait timed out after 10002ms" 我在Protractor Cucumber框架中工作,如果在页面中找不到元素或无法单击元素,则不会出现原生硒错误,例如``找不到元素''或``找不到这样的元素''或``元素不可点击''。我收到“ TimeoutError:10002ms后等待超时”

Only if i get these errors I will come to know i have made some mistake in my element xpath or I have tried to click a disabled button etc. 只有当我得到这些错误时,我才会知道我在元素xpath中犯了一些错误,或者我试图单击禁用的按钮等。

Generic error like time out does not help me fix the failed test cases easily. 诸如超时之类的通用错误无法帮助我轻松修复失败的测试用例。

Below is my code.contactPage.js is the implementation.util.js is some helper methods in my framework 下面是我的代码。contactPage.js是实现。util.js是我框架中的一些帮助方法

File contactPage.js 文件contactPage.js

  var contact = element(by.xpath("//p[contains(text(),'Contact Me')]"));

   function clickUserGuide() {
   return util.isDisplayed(contact, 10000).then(() => {
    return util.clickElement(contact, 10000);
});

File util.js 文件util.js

function isDisplayed(element, milliseconds) {
return browser.wait(EC.visibilityOf(element), milliseconds).then(() => {
    return element.isDisplayed();
  });
};
function clickElement(element, milliseconds) {
 return browser.wait(EC.visibilityOf(element), milliseconds).then(() => {
    element.click();
    return true;
 });
}; 
}

The reason why you are getting TimeoutError: Wait timed out after 10002ms is because of the method browser.wait(EC.visibilityOf(element), milliseconds) you are using. 之所以会出现TimeoutError: Wait timed out after 10002ms是因为您使用的方法browser.wait(EC.visibilityOf(element), milliseconds)

The method doesn't have a fail "hard" like the No Such Element Found , it just keeps waiting for the element to match the expected condition, in your case you are waiting for: 该方法没有“ No Such Element Found ”那样的“困难”失败,它只是一直在等待元素匹配预期条件,在这种情况下,您正在等待:

  1. the element is be displayed 显示元素
  2. AND the height and width to be greater than 0 AND的高度和宽度大于0

If this doesn't happen in the given amount of seconds the condition fails with a message that the element couldn't match the condition within the given time. 如果在给定的秒数内没有发生这种情况,则条件将失败,并显示一条消息,指出元素在给定时间内不符合条件。

What happens is you use browser.wait(EC.presenceOf(element), milliseconds) , is the element really present in the DOM? 您使用browser.wait(EC.presenceOf(element), milliseconds)会发生什么,该元素确实存在于DOM中吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium或Protractor获取HTML中嵌套元素的文本以实现自动化? - How do i get the text of a nested element in HTML for automation using Selenium or Protractor? 量角器,使用 isDisplayed() 我得到 NoSuchElementError: No element found using locator - Protractor, with isDisplayed() I get NoSuchElementError: No element found using locator 量角器+角度误差-元素在点不可单击 - Protractor + angular error - Element is not clickable at point 如何获得html元素的可点击点? - How do get I the clickable point from a html element? Selenium使用Protractor获取元素的所有内部文本 - Selenium get all inner text of an element with Protractor 如果定义了元素,为什么我会得到 elem is not defined 错误? - Why do I get the elem is not defined error if element is defined? 如何在 selenium python 中获取“$3”元素值的值 - How do I get the value of a "$3" element value in selenium python materializecss日期选择器量角器(错误:元素在点处不可单击) - materializecss date-picker protractor (Error: Element is not clickable at point ) 失败:未知错误:元素在点(x,x)处无法点击 - 角度/量角器 - Failed: unknown error: Element is not clickable at point (x, x) - Angular/Protractor 使用Jmeter / Blazemeter时,出现错误org.openqa.selenium.NoSuchElementException:无法找到元素: - When using Jmeter/ Blazemeter I get the error org.openqa.selenium.NoSuchElementException: Unable to locate element:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM