Selenium : How to send variable character strings through executeScript()(Selenium:如何通过 executeScript() 发送可变字符串)
问题描述
我需要在系统中进行一些自动测试.有些字段得到了验证,它可能不能仅仅通过 sendKeys
来完成(然后我正在这样做,它只是写了一个字符串,而不是整个字符串.尝试通过字符串迭代 sendKeys,没有也可以工作)
I need to do some automatic tests within system. Some fields got validations, and it probably can't be done by just sendKeys
(then I'm doing it, it just write some one string, not whole. Tried iterating sendKeys thru string, didn't work either)
现在我正在尝试通过 javascript 向字段输入值.有类似的东西:
Right now I'm trying to input value to field by javascript. Got something like it:
WebElement pesel = driver.findElement(fldPesel);
jse.executeScript("arguments[0].value='80120804076';", pesel);
但是,我不希望在 executeScript 中具有值,而是在 java 变量中具有值,因此它看起来和工作得更好.并得到了一些随机化
But, I would want not to have value in executeScript, but java variable, so it would look and work better. And got some randomisation
我怎么能这样做?
推荐答案
根据你的说法我不希望在 executeScript 中有值,但是 java 变量你可以引用 Sting 通过 Java 变量获取值:
As per your statement I would want not to have value in executeScript, but java variable you can reference the Sting value through a Java variable :
String myValue = "80120804076";
WebElement pesel = driver.findElement(fldPesel);
jse.executeScript("arguments[0].value='" + myValue + "';", pesel);
这篇关于Selenium:如何通过 executeScript() 发送可变字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Selenium:如何通过 executeScript() 发送可变字符串


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01