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

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

问题描述

我连续有3个文本框,我正在使用JS在文本框中输入文本.但问题是当我在一个字段中输入文本并转到第二个框输入文本时,第一个文本框中的值被删除.我们正在使用下面的代码来输入文本

((JavascriptExecutor) webDriver).executeScript("arguments[0].setAttribute('value','"+inputText+"')",元素);

解决方案

试试下面的:

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

<块引用>

确保在第二个和第三个text被推送之前,document.readyState == "complete"已经实现.

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

解决方案

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.

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

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