Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用sendkeys生成增量版本号_Javascript_Eclipse_Selenium - Fatal编程技术网

Javascript 如何使用sendkeys生成增量版本号

Javascript 如何使用sendkeys生成增量版本号,javascript,eclipse,selenium,Javascript,Eclipse,Selenium,我正在测试一个.gov网站,我想在我的java脚本中添加一个递增的版本号。网站不能有重复的帐户标题条目或版本号 我搜索过谷歌和youtube,但什么也找不到 我目前使用的代码是: driver.findElement(By.xpath("//input[@name='title']")).sendKeys("e2e01"); 上面的代码进入e2e01。我希望我的代码在每次运行脚本时将版本号增加+1,或者在e2e末尾生成一个随机数,使其进入e2e02,然后进入e2e03,依此类推。我建议

我正在测试一个.gov网站,我想在我的java脚本中添加一个递增的版本号。网站不能有重复的帐户标题条目或版本号

我搜索过谷歌和youtube,但什么也找不到 我目前使用的代码是:

    driver.findElement(By.xpath("//input[@name='title']")).sendKeys("e2e01");

上面的代码进入e2e01。我希望我的代码在每次运行脚本时将版本号增加+1,或者在e2e末尾生成一个随机数,使其进入e2e02,然后进入e2e03,依此类推。

我建议您创建一个XML文件,作为测试的数据提供者。在每次运行中,它会递增编号并更新XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<vars>
  <counter>1</counter>
</vars>
在您的sendKeys中:

driver.findElement(
By.xpath("//input[@name='title']")).sendKeys("e2e0" + Integer.toString(incrementCounter()));

我建议您创建一个XML文件,作为测试的数据提供者。在每次运行中,它会递增编号并更新XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<vars>
  <counter>1</counter>
</vars>
在您的sendKeys中:

driver.findElement(
By.xpath("//input[@name='title']")).sendKeys("e2e0" + Integer.toString(incrementCounter()));

您好,这是类似的代码,您可以在java中转换,这是我在python中完成的,供您参考

from selenium import webdriver
import traceback
from builtins import str
from robot.utils.error import Throwable

driver = webdriver.Ie("C:/automation/config/IEDriverServer.exe")
driver.get("https://www.w3schools.com/")
driver.maximize_window()
driver.find_element_by_xpath("/html/body/div[5]/div/a[1]/i").click()
test=True;
loopCounter=0;
try:
    while (test):
    loopCounter += 1
    if (loopCounter == 20):
        test=False
        break
    else:
        driver.find_element_by_css_selector("#gsc-i-id1").send_keys("e2e" + str(format(loopCounter, '02d')))
        driver.find_element_by_css_selector("#gsc-i-id1").clear()

except :
    Throwable(traceback)

您好,这是类似的代码,您可以在java中转换,这是我在python中完成的,供您参考

from selenium import webdriver
import traceback
from builtins import str
from robot.utils.error import Throwable

driver = webdriver.Ie("C:/automation/config/IEDriverServer.exe")
driver.get("https://www.w3schools.com/")
driver.maximize_window()
driver.find_element_by_xpath("/html/body/div[5]/div/a[1]/i").click()
test=True;
loopCounter=0;
try:
    while (test):
    loopCounter += 1
    if (loopCounter == 20):
        test=False
        break
    else:
        driver.find_element_by_css_selector("#gsc-i-id1").send_keys("e2e" + str(format(loopCounter, '02d')))
        driver.find_element_by_css_selector("#gsc-i-id1").clear()

except :
    Throwable(traceback)

谢谢您的回复,上面的内容每次运行时都会给我一个计数器,有没有办法在增量之前添加字符e2e?谢谢您的回复,上面的内容每次运行时都会给我一个计数器,有没有办法在增量之前添加字符e2e?这个答案充满了不相关的代码,这些代码使用了错误的做法,并且是用不同的语言编写的。这有什么帮助?这个答案充满了不相关的代码,这些代码使用了不好的实践,并且是用不同的语言编写的。这有什么帮助?