如何使用 Selenium 和 java 生成随机用户 ID 并在文本框中填写

How to generate random user id and fill with in a text box using Selenium and java

我正在使用一个应用程序,每次我都需要创建一个新用户。我想要可以通过正则表达式为我生成相同内容的代码。示例- Alen001Alen002Alen003 等等。

driver.findElement(By.id("userId")).sendKeys("Alen001");

创建一个新的随机用户 ID,例如Alen001, Alen002, Alen003 等,通过 sendKeys() 就可以使用以下代码行:

driver.findElement(By.id("userId")).sendKeys("Alen00"+ Integer.toString(((new Random().nextInt(10))+1)));