gpt4 book ai didi

javascript - Selenium : How to send variable character strings through executeScript()

转载 作者:行者123 更新时间:2023-11-30 20:38:01 24 4
gpt4 key购买 nike

我需要在系统内做一些自动测试。有些字段得到了验证,它可能不能仅通过 sendKeys 来完成(然后我正在这样做,它只写一些字符串,而不是整个字符串。尝试通过字符串迭代 sendKeys,没有要么工作)

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

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

但是,我不想在 executeScript 中有值,而是在 java 变量中有值,这样它看起来和工作起来会更好。并进行了一些随机化

我怎么做到的?

最佳答案

根据你的陈述我不想在 executeScript 中有值,但是 java 变量你可以通过 Java 引用 Sting 值变量:

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

关于javascript - Selenium : How to send variable character strings through executeScript(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49596978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com