Selenium:如何通过executeScript()发送可变字符串 [英] Selenium : How to send variable character strings through executeScript()

查看:260
本文介绍了Selenium:如何通过executeScript()发送可变字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在系统内进行一些自动测试.有些字段已经过验证,可能仅通过sendKeys不能完成(然后我正在做,它只写了一个字符串,而不是整个字符串.尝试通过字符串迭代sendKeys,也不起作用)

现在我正在尝试通过javascript将值输入字段.有类似的东西:

WebElement pesel = driver.findElement(fldPesel);
jse.executeScript("arguments[0].value='80120804076';", pesel);

但是,我不想在executeScript中有值,而是在Java变量中有值,因此它看起来和工作起来会更好.并得到一些随机化

我该怎么做?

解决方案

按照您的声明我不希望在executeScript中具有任何值,但是Java变量您可以引用 Sting 值通过 Java 变量:

String myValue = "80120804076";
WebElement pesel = driver.findElement(fldPesel);
jse.executeScript("arguments[0].value='" + myValue + "';", pesel);

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)

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

But, I would want not to have value in executeScript, but java variable, so it would look and work better. And got some randomisation

How I could do that?

解决方案

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()发送可变字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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