Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

javascript - Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted

I have 3 text box in a row, and I am using JS to input the texts in the text boxes. But the problem is when I enter the text in one field, and go to second box to enter the text, the value from first text box is removed. we are using the below code to input text

((JavascriptExecutor) webDriver).executeScript(
  "arguments[0].setAttribute('value','"+inputText+"')",
  element);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try the following :

String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) webDriver).executeScript(js, element);

Ensure that the before the second and third text is being pushed the document.readyState == "complete" is achieved.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...