Search code examples
javaseleniumselenium-webdriverrandomuuid

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


I need help in selenium script. I need to take random alphanumeric values from my table list. How I can do it in selenium? I want to use

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

This in my selenium script. But I don't know how to use?


Solution

  • As mentioned in my comment, it won't be possible to match the newly generated UUID.randomUUID().toString() with any of the the predefined values within your table list.

    However, to generate and send a random number to the Search Box on Google Home Page you can use the following solution:

    • Code Block:

      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());
          }
      }
      
    • Browser Snapshot:

    random_UUID