Selenium - Java - Sendkeys 在文本字段中不起作用没有错误

问题描述

我在 Eclipse 环境中使用 Selenium 和 Java 来自动化网站上的测试用例。这是个人学习。 以下是html代码。

enter image description here

我在 Maven 项目中使用页面对象模型。当我尝试在文本字段上使用 sendkeys 方法时,它不起作用。没有错误。测试用例成功通过。但文本未在文本字段中输入。我尝试在输入文本之前单击文本字段。它确实单击但它不键入任何内容。可能是什么问题呢。硒版本 - 3.141。 Eclipse 版本 - 4.7。以下是我的页面文件中的代码

package seleniumeasy.qa.Page;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import seleniumeasy.qa.Base.Base;

public class tblDataSearchPage extends Base{

    @FindBy(xpath="//div[@class='panel-body']/input")
    WebElement txtSearch;
    
    public tblDataSearchPage()
    {
        PageFactory.initElements(driver,this);
    }
    
    public void searchElement()
    {
        //txtSearch.click();
        txtSearch.clear();
        txtSearch.sendKeys("smith");
        txtSearch.sendKeys(Keys.RETURN);
                
    }
}

以下是我的测试课

package seleniumeasy.test.Tests;

import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

import seleniumeasy.qa.Base.Base;
import seleniumeasy.qa.Page.tblDataSearchPage;
import seleniumeasy.qa.Page.tblPaginationPage;

public class tblDataSearchTest extends Base
{

    SoftAssert sAssert;
    tblPaginationPage tObj;
    tblDataSearchPage obj;
    
    public tblDataSearchTest()
    {
        Init();
        sAssert = new SoftAssert();
        tObj=new tblPaginationPage();
        obj = tObj.clickTableDataSearchMenu();      
    }
    @Test
    public void verifySearchElement()
    {
        obj.searchElement();
    }
    /*@Test
    public void verifySearchElementBasedOnUsername()
    {
        boolean bTestPass = obj.searchFilterName();
        
        
    }*/
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)