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

Selenium - Java - Sendkeys not working in textfield. No error

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

我在 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);
                
    }
}

以下是我的测试class

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();
        
        
    }*/
}
txtSearch.click()
WebElement currentElement = driver.switchTo().activeElement();
currentElement.sendKeys("something")

你能试试这个吗