[英]How to write selenium script for taking random alphanumeric number from a list
我需要硒腳本方面的幫助。 我需要從表列表中獲取隨機的字母數字值。 我如何用硒做到這一點? 我想用
String uniqueID = UUID.randomUUID().toString();
這在我的硒腳本中。 但是我不知道怎么用?
如我的評論中所述,將新生成的UUID.randomUUID().toString()
與表列表中的任何預定義值進行匹配都是不可能的。
但是,要生成隨機數並將其發送到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()); } }
瀏覽器快照:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.