如何编写用于从列表中获取随机字母数字的 selenium 脚本

How to write selenium script for taking random alphanumeric number from a list

我需要 selenium 脚本方面的帮助。我需要从我的 table 列表中随机取字母数字值。我怎么能在硒中做到这一点?我想使用

String uniqueID = UUID.randomUUID().toString(); 

这在我的 selenium 脚本中。但是不知道怎么用?

如我的评论所述,无法将新生成的 UUID.randomUUID().toString() 与 table 列表中的任何预定义值相匹配。

但是,生成并发送一个随机数Google主页上的搜索框页可以使用以下解决方法:

  • 代码块:

    import java.util.UUID;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class RandomNumbers_GoogleSearchBox {
    
        public static void main(String[] args) {
    
            System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
            WebDriver driver = new FirefoxDriver();
            driver.get("https://www.google.com/");
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.name("q"))).sendKeys(UUID.randomUUID().toString());
        }
    }
    
  • 浏览器快照: