首页 > 解决方案 > 无法在页面对象类中使用 WebElements 对象

问题描述

一般来说,我是 Selenium 和 java 的新手。我正在尝试将 Page 对象模型与 Page 工厂一起使用来为应用程序的登录页面创建 Page 对象类。当我创建一个方法时,WebElement 对象错误指示以下内容:错误消息。我见过其他的 webelements 不必是静态的演示。我不知道我做错了什么。

package com.imis.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import Actiondriver.ImisActionclass;
import Base.basepackage;

public class login extends basepackage {
    
    @FindBy(xpath="//input[@id='ctl01_TemplateBody_WebPartManager1_gwpciSignIn_ciSignIn_signInUserName']")
     WebElement userName;
    
    @FindBy(xpath="//input[@id='ctl01_TemplateBody_WebPartManager1_gwpciSignIn_ciSignIn_signInPassword']")
     WebElement password;
    
    @FindBy(xpath="//input[@id='ctl01_TemplateBody_WebPartManager1_gwpciSignIn_ciSignIn_SubmitButton']")
     WebElement submitButton;

    public login() {
        PageFactory.initElements(driver, this);
        }
    
    public static void loginpage(String uname, String pswd) {
        ImisActionclass.type(userName, text);
        ImisActionclass.type(pswd, password);
        ImisActionclass.click(driver, submitButton);
    

标签: selenium-webdriverpage-factory

解决方案


推荐阅读