使用JS输入文本,但如果我在一个文本框中输入文本,则已输入的值将被删除 [英] Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted

查看:84
本文介绍了使用JS输入文本,但如果我在一个文本框中输入文本,则已输入的值将被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连续有3个文本框,我使用JS在文本框中输入文本。但问题是当我在一个字段中输入文本,然后转到第二个框输入文本时,将删除第一个文本框中的值。我们使用以下代码输入文本

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


推荐答案

请尝试以下方法:

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




确保在第二个和第三个<$ c之前正在推送$ c> text document.readyState ==complete

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

这篇关于使用JS输入文本,但如果我在一个文本框中输入文本,则已输入的值将被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆