我需要有关 Selenium 脚本的帮助。我需要从表列表中获取随机字母数字值。我怎样才能用 Selenium 做到这一点?我想使用
String uniqueID = UUID.randomUUID().toString();
这在我的 Selenium 脚本中。但不知道怎么用?
最佳答案
正如我的评论中提到的,不可能将新生成的 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()); } }
浏览器快照:
关于java - 如何编写 Selenium 脚本从列表中获取随机字母数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665235/