問題描述
我需要在系統中進行一些自動測試.有些字段得到了驗證,它可能不能僅僅通過 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() 發送可變字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!