- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
目标:使用 PageObject 检查当前页面上是否存在元素/IWebElement。
我知道你可以使用类似的东西:
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("foo")));
但是当我使用 PageObjects 时,我不想再次使用 id/xpath 等。我目前正在使用下面的方法来检查元素是否存在。但是为了快速做到这一点,我首先设置了隐式等待,然后将其重置为默认值。它工作得很好,但感觉很脏。
我发现了一些其他较旧的帖子。但这还没有为我提供任何解决方案。希望对您有所帮助!
页面对象:
[FindsBy(How = How.Id, Using = "errorMessage")]
public IWebElement btnSubmit { get; set; }
调用方法:
CheckElementExists(errorMessage))
方法;
public bool CheckElementExists(IWebElement pageObject)
{
Browser.getDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
try
{
return pageObject.Equals(pageObject);
}
catch (NoSuchElementException)
{
return false;
}
finally
{
Browser.getDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
}
}
最佳答案
我没有使用 C# 的经验,但我认为它与 JAVA 非常相似,因此您可以在 C# 中转换以下 JAVA 代码。
如果只想编写函数来检查元素是否存在,这就是您可以做到的。
public boolean isElementExisit(WebElement element){
try{
element.getTagName();
return true;
}catch (NoSuchElementException){
return false;
}
}
如果你想写一些需要等待的东西,那么你可以使用流畅的等待。
public void waitUntilElementIsPresent(WebElement element, int timeout){
Wait wait = new FluentWait<WebDriver>(driver)
.withTimeout(timeout, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
wait.until(new Function() {
@Override
public Boolean apply(Object o) {
element.getTagName();
return true;
}
});
}
关于c# - Selenium C# 使用 PageObject 检查 IWebElement 是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45238065/
我刚开始使用 WebDriver ,我正在尝试学习最佳实践,特别是使用 PageObjects和 PageFactory . 我的理解是PageObjects应该暴露网页上的各种操作,并将WebDri
所以我有一个页面对象,它处理用户所在页面的所有主要功能。我想这样做,这样当调用页面对象的实例时就会发生一些事情。在当前情况下,我有: public MyPageObject MY_SCREEN = n
所以,当出现问题时,我只是在创建一个简单的 selenium/JBehave 代码。 我会先贴出简化的代码,稍后再解释我的问题。 所以这里我们有一个简单的抽象类,它将在我的 PageObjects 上
我正在尝试为 WebDriver 中的页面对象创建某种代码生成。 我读到了它,并观看了下一个讲座: http://www.youtube.com/watch?v=mSCFsUOgPpw 我还看到一些工
如何为页面中的框架实现 pageObject 模式(Selenium)..我有一个主页,有一个左框架和右框架,我想为每个框架创建页面对象.. 例如,我有如下的 LeftFrame 页面对象: Publ
有没有办法从另一个页面对象文件访问一个页面对象文件中定义的元素? 例子:如果我们需要从 LoginPage.ts 文件访问“@usernameInput”,是否需要从 HomePage.ts 复制它?
我想从下面知道哪个是创建 PageObject 类实例的更好选择(例如:LoginPage):- 1) 在所有测试和步骤中创建一个 Pageobject 类的实例(任何需要的地方)? LoginPag
我想我已经掌握了 PageObject 模式的要点,但其中有些部分我还没有掌握。 所以我一直在学习本教程,现在我有了这个 Page 类: public class SignUpPage extends
如果一个按钮可选地显示在页面(或页面的一部分)上,它是否有资格将该部分表示为两个不同的 PageObjects,其中一个 PageObject 提供与按钮交互的方法,而另一个 PageObject 不
我有一些基本的 selenium 和 java 经验,但我正在尝试了解有关页面对象模式的更多信息,并且在完全理解如何在实际项目中使用它时遇到了一些问题。我尝试在谷歌中寻找简单但实用的项目,我可以复制并
page-object gem自动 generates multiple accessors . 例如,除了 link 之外,您还可以使用 links,例如: class MyPage inc
我正在编写一些 Selenium 测试,想知道如何导航到我的 ProfilePage,只需在我的测试中调用它的类即可所以我得到了我的 BasePage 类, class BasePage(object
我正在使用 Cheezy Page Object gem(这也意味着我正在使用 Watir,这也意味着我正在使用 Selenium)。我还明确加载了 watir gem。 无论如何,我有一个网站,我正
将 PageObjects 模式应用于页面组件时的标准方法是什么? 举个例子,假设我正在为亚马逊产品页面上的功能编写测试。 该页面包含大量单独的功能、产品信息、查看此内容的客户、推荐的其他客户等。 我
本文整理了Java中com.atlassian.webdriver.pageobjects.WebDriverTester类的一些代码示例,展示了WebDriverTester类的具体用法。这些代码示
我们的应用程序具有消耗组件的组件,这些组件消耗具有不同复杂性的组件。所以我只想要页面上的输入,以验证何时设置对象文本是否正确。问题是它是这些子组件之一。 我的同事告诉我,有两种方法可以做到这一点,第一
我对 Selenium 非常陌生,我开始自动化登录过程。我为此目的使用了 PageObjects。我有一个 LoginPage ,它有一个这样的方法: public MyHomePage login(
我正在尝试使用 WebdriverIO Docs 中定义的语法定义一个 PageObject : 父页面 //page.js export default class Page { constru
我试图找到这个问题的答案,但没有一个对我有帮助。我确定我遗漏了一个细节,但我无法弄清楚到底是什么。 运行测试用例时出现NullPointerException。我认为当我尝试将驱动程序传递给我的页面对
我正在使用 PageObjects 在 Selenium Webdriver 中制作一个测试套件,但我怀疑即使驱动程序指向不同的框架,WebElement 引用的实例是否也可以工作?我正在为其编写测试
我是一名优秀的程序员,十分优秀!