标签: page-factory

Selenium @FindBy vs driver.findElement()

我为什么要用@FindByvs driver.findElement()

@FindBy强迫我将所有变量移动到类级别(当大多数变量只需要在方法级别时).它似乎唯一能给我买的是我可以调用PageFactory.initElements(),它为我处理延迟初始化.

我错过了什么?

selenium annotations findby selenium-webdriver page-factory

27
推荐指数
1
解决办法
5万
查看次数

PageFactory中的StaleElementReference异常

我正在尝试学习PageFactory模型.我理解这样一个事实,当我们这样做时initElements,WebElements就位于其中.比如说,我点击了一个webelement,因此DOM中的其他一个元素发生了变化.现在,显然我会在StaleElementReferenceException这里得到一个.我该如何解决这个问题?

我是否应该再次发现特定的WebElement知道DOM中的WebElement属性可能发生了变化?还是有另一种方法来处理这个问题?

selenium pageobjects selenium-webdriver page-factory staleelementreferenceexception

10
推荐指数
2
解决办法
4670
查看次数

当前上下文中不存在名称"PageFactory"

我正在用c#创建一个测试自动化框架.在项目中,我有"的顶部使用OpenQA.Selenium.Support.PageObjects;",但是当我尝试引用PageFactory.initElements(驱动程序,页面名称),我看到消息"名'PageFactory’不存在中目前的背景".

我认为PageFactory类是作为Selenium.Support nu get包的一部分包含的.在线教程似乎以与我没有额外导入相同的方式引用PageFactory,有什么我缺少的吗?

NuGet包:

  • 使用Selenium.WebDriver版本3.9.1
  • 使用Selenium.Support版本3.9.1
  • 使用NUnit 3.9.0
  • 使用NUnit3TestAdapter 3.9.0
  • Microsoft.NET.Test.Sdk 15.5.0
  • 代码如下:

    using NUnit.Framework;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Support.PageObjects;
    using System;
    using System.IO;
    
    namespace Framework.TestCases
    {
        class TestCase
        {
            [Test]
            public void Test()
            {
                String pathToDrivers = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Drivers";
                IWebDriver driver = new ChromeDriver(pathToDrivers);
                String searchTerm = "Search Term";
    
                driver.Url = "https://website.com/";
                driver.Manage().Window.Maximize();
    
                HomePage homePage = new HomePage(driver);
                PageFactory.initElements(driver, homePage);
            }
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

    c# selenium page-factory

    8
    推荐指数
    3
    解决办法
    4079
    查看次数

    Appium - 在 PageFactory 获取 java.lang.RuntimeException:java.lang.NoSuchMethodException:jdk.proxy2.$Proxy9.proxyClassLookup()

    我在运行 Appium 测试时遇到此异常。PageFactory 上的测试失败,但出现以下异常。

    \n
    My POM:\n<?xml version="1.0" encoding="UTF-8"?>\n<project xmlns="http://maven.apache.org/POM/4.0.0`\n         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\n    <modelVersion>4.0.0</modelVersion>\n\n    <groupId>com.telepathy.test</groupId>\n    <artifactId>twitter</artifactId>\n    <version>1.0-SNAPSHOT</version>\n    <dependencies>\n        <dependency>\n            <groupId>junit</groupId>\n            <artifactId>junit</artifactId>\n            <version>4.12</version>\n        </dependency>\n        <!-- https://mvnrepository.com/artifact/io.appium/java-client -->\n        <dependency>\n            <groupId>io.appium</groupId>\n            <artifactId>java-client</artifactId>\n            <version>7.2.0</version>\n        </dependency>\n    </dependencies>\n\n</project>\n\n
    Run Code Online (Sandbox Code Playgroud)\n
      \n
    • 直到昨天,这一切都工作正常,我的机器重新启动,这个错误开始出现。
    • \n
    • 已经尝试过最新版本的 Appium (7.5.1)
    • \n
    • mvn清理刷新了吗,更新
    • \n
    \n

    此处失败:\nPageFactory.initElements(new AppiumFieldDecorator(this.driver), this);

    \n
    java.lang.RuntimeException: java.lang.NoSuchMethodException: \n    jdk.proxy2.$Proxy9.proxyClassLookup()\n    at  \xe2\x80\x8bio.appium.java_client.pagefactory.bys.builder.AppiumByBuilder.prepareAnnotationMethods(\nApiumByBuilder.java:84)\n
    Run Code Online (Sandbox Code Playgroud)\n

    automation pom.xml appium page-factory appium-android

    6
    推荐指数
    1
    解决办法
    1万
    查看次数

    使用反射获取Pagefactory WebElement名称

    我正在使用Selenium pagefactory,并引入了一个注释@Name(Description =“ Username”),我将其用于所有WebElement。稍后,我需要在自定义方法中找到Description的值,以进行报告,例如:

    public static void click(WebElement element) throws Throwable {
            try {
                element.click();
            } catch(ElementNotInteractableException E1) {
                throw new UnableToInteractWithElementException("Unable To Interact With " + WebElement Descriptionn);
            }
        }
    
    Run Code Online (Sandbox Code Playgroud)

    我的@Name批注界面和pagefactory如下所示:

    名称界面

    @Target({ElementType.FIELD, ElementType.TYPE,ElementType.CONSTRUCTOR})
    public @interface Name {    
        String Description() default "";
    }
    
    Run Code Online (Sandbox Code Playgroud)
    @Name(Description = "Username")
    @FindBy(id="txtLoginID")
    public WebElement username;
    
    Run Code Online (Sandbox Code Playgroud)

    我在使用反射时遇到的问题是需要定义pagefactory的类名,还需要提供字段名作为字符串“ username”来检索注释值。

    我希望能够仅通过提供我的WebElement而不向click(WebElement element)方法提供其他对象来检索注释值。

    java reflection selenium selenium-webdriver page-factory

    5
    推荐指数
    1
    解决办法
    159
    查看次数

    如何使用 Selenium 和 Java 通过 PageFactory 等待元素不可见

    有没有办法使用 PageFactory 注释等待 Selenium 中不存在的元素?

    使用时:

    @FindBy(css= '#loading-content')
    WebElement pleaseWait;
    
    Run Code Online (Sandbox Code Playgroud)

    定位元素,然后:

    wait.until(ExpectedConditions.invisibilityOfElementLocated(pleaseWait));
    
    Run Code Online (Sandbox Code Playgroud)

    我会得到:

    org.opeqa.selenium.WebElement cannot be converted to org.openqa.selenium.By
    
    Run Code Online (Sandbox Code Playgroud)

    我可以使用以下方法完成我需要的操作:

    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector('loading-content')));
    
    Run Code Online (Sandbox Code Playgroud)

    但是,我希望能够使用 PageFactory 注释以保持框架一致。有没有办法做到这一点?

    java selenium pageobjects page-factory webdriverwait

    5
    推荐指数
    1
    解决办法
    5295
    查看次数

    Selenium Page对象:为什么要返回此值?

    通过阅读SeleniumHQ的pageobject文档,他们指定了从不导航到其他页面的方法返回“ this”的示例。我的问题是为什么?

    我以为页面对象的状态可能是一个原因,但是页面本身(实际的UI页面)可能会更改状态或刷新,但页面对象本身不会。Page Factory及其@FindBy批注已经确保了每次调用WebElement时都会找到它,因此在这种情况下元素的状态似乎无关紧要。

    selenium pageobjects page-factory

    1
    推荐指数
    1
    解决办法
    981
    查看次数