1

I am new to Selenium testing, I am trying to put the value into the textbox with the help of xpath, name & id. (java using eclipse IDE):

   driver.findElement(By.xpath(".//* [@id='txtEmpDepAddressLine1']")).sendKeys("2nd Main")   
   driver.findElement(By.xpath(".//*[@id='txtEmpDepAddressLine2']")).sendKeys("Bangalore");

While running, textbox is not retrieve the from the above code. Can anyone help me out to solve this problem?

6
  • 1
    An HTML to support your question would be helpfull. Commented Jan 19, 2015 at 11:25
  • Are you getting any exception? Commented Jan 20, 2015 at 7:12
  • there is no Exceptions,In the text box it is fetching the value but it can't able not store in the text box field. Commented Jan 20, 2015 at 10:18
  • @PiotrBoho i am not Getting Any Error,While running the project it is retrieving, but it is not storing the values in the text box.As it is a required field so it is Displaying Validation Error. Commented Jan 20, 2015 at 10:51
  • put a breakpoint in sendKeys() line run test in debug mode. when you reach the breakpoint enter the same string manually in browser. and continue running test. and tell me the result Commented Jan 20, 2015 at 11:58

3 Answers 3

1

Use By.id instead By.xpath

If you insist xpath then: Start with: // instead: .//

Make sure the id value is unique on page.

if using xpath in some browsers id or ID makes differnce.

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

1 Comment

Thank u.But i tried with Id as well as Using By.name Also except for two text box remaining fields are working properly.
0

It is difficult to say without the HTML, but I'd suggest a few things:

  1. Open your page, go to the Google Chrome DevTools console, and verify you can locate the element using your xpath. So you'd type:

$x("//* [@id='txtEmpDepAddressLine1']")

and verify the text box is located.

  1. If the sendKeys isn't working on the element at that id, I'd wonder if it is not on the text field itself, but on a containing table or something like that. Make sure the element located by the id is the input, so the sendKeys will work.

Comments

0

By

In the text box it is fetching the value but it can't able not store in the text box field

do you mean you can see selenium typing those values into the textbox and then the values disappear?

If that is what is happening, it is possible there is some javascript running on the page while selenium is entering the values in the textbox. you can try to put a wait before selenium enters the value. If waiting resolves the issue, you will need to write a method to detect when the javascript is done.

Comments

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.