0

I am using Selenium using Java in Eclipse environment to automate testcases on website. This is for personal learning. Following is the html code.

enter image description here

I am using Page Object Model in Maven project. When I try to use sendkeys method on the textfield it does not work. There is no error. The testcase passes successfully. But text is not typed in the textfield. I tried clicking on the textfield before entering text. It does click but it does not type anything. What could be the problem. Selenium Version - 3.141. Eclipse version - 4.7. Following is the code in my Page file

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

Following is my test 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();
        
        
    }*/
}
4
  • please add you test classs Commented Jan 8, 2021 at 16:38
  • added test class Commented Jan 10, 2021 at 1:12
  • on further investigation, this seems to be a problem only with chrome driver. In firefox it is working fine. Commented Jan 10, 2021 at 2:13
  • Now I downloaded the latest chromedriver (87.0.4280.88) and ran the program still the same problem. Commented Jan 10, 2021 at 2:56

1 Answer 1

1
txtSearch.click()
WebElement currentElement = driver.switchTo().activeElement();
currentElement.sendKeys("something")

Could you try this

Sign up to request clarification or add additional context in comments.

1 Comment

@Jay could you accept the answer also by clicking the tick sign

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.