我想使用硒同时填写所有“文本”字段。我将如何在Java中执行此操作?使用此代码,当我执行代码时,每个Text字段都会被一个又一个的填充,这很慢
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement fullname = driver.findElement(By.id("order_billing_name"));
js.executeScript("arguments[0].value='Test Name';", fullname);
WebElement email = driver.findElement(By.id("order_email"));
js.executeScript("arguments[0].value='test123@gmail.com';", email);
WebElement tel = driver.findElement(By.id("order_tel"));
js.executeScript("arguments[0].value='12345678901';", tel);
WebElement address = driver.findElement(By.id("bo"));
js.executeScript("arguments[0].value='123 Main Street';", address);
WebElement city = driver.findElement(By.id("order_billing_city"));
js.executeScript("arguments[0].value='London';", city);
WebElement postcode = driver.findElement(By.id("order_billing_zip"));
js.executeScript("arguments[0].value='LE1 123';", postcode);
WebElement number = driver.findElement(By.id("cnb"));
js.executeScript("arguments[0].value='1234567890123456';", number);
WebElement cvv = driver.findElement(By.id("vval"));
js.executeScript("arguments[0].value='123';", cvv);
答案 0 :(得分:0)
尝试一下:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("order_billing_name"))).sendKeys("Test Name");
wait.until(ExpectedConditions.elementToBeClickable(By.id("order_email"))).sendKeys("test123@gmail.com");
wait.until(ExpectedConditions.elementToBeClickable(By.id("order_tel"))).sendKeys("12345678901");
wait.until(ExpectedConditions.elementToBeClickable(By.id("bo"))).sendKeys("123 Main Street");
wait.until(ExpectedConditions.elementToBeClickable(By.id("order_billing_city"))).sendKeys("London");
wait.until(ExpectedConditions.elementToBeClickable(By.id("order_billing_zip"))).sendKeys("LE1 123");
wait.until(ExpectedConditions.elementToBeClickable(By.id("cnb"))).sendKeys("1234567890123456");
wait.until(ExpectedConditions.elementToBeClickable(By.id("vval"))).sendKeys("123");