Согласно вашему опубликованному HTML. Вы можете попробовать с индексами, если поле того же типа.
Используйте код ниже:
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(1)")).sendKeys("your value"); // for first text box
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(2)")).sendKeys("your value"); // for Second text box
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(3)")).sendKeys("your value"); // for third text box
Пожалуйста, измените index
в div[class='field-set'] input.input-pin:nth-child(index)
согласно текстовому полю в позиции пользовательского интерфейса страницы.
UPDATE
Если вы не уверены, какое текстовое поле должно принимать значение, используйте следующую логику
public static void main(String[] args) {
// first you need to store your testdata in a collection
Map<String,String> pinCodes = new HashMap<String, String>();
pinCodes.put("pin1", "2");
pinCodes.put("pin2", "3");
pinCodes.put("pin3", "3");
pinCodes.put("pin4", "4");
// you can remove the values as per you need suppose you only want `pin1` `pin2` then remove `pinCodes.put("pin3", "3");` and `pinCodes.put("pin4", "4");` from above code
enterPinCode(pincodes); //call method to enter the values in corresponding text-boxes
}
public void enterPinCode(Map<String,String> pinCodes) {
for (Entry<String, String> entry : pinCodes.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
switch (key) {
case "pin1" :
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(1)")).sendKeys(value);
break;
case "pin2" :
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(2)")).sendKeys(value);
break;
case "pin3" :
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(3)")).sendKeys(value);
break;
case "pin4" :
driver.findElement(By.cssSelector("div[class='field-set'] input.input-pin:nth-child(4)")).sendKeys(value);
break;
default :
System.out.println("pincode textbox key not found");
break;
}
}
}
ИЛИ, если флажок является динамическим на веб-странице, замените приведенный ниже код в выражении switch
:
switch (key) {
case "pin1" :
List<WebElement> box1 = driver.findElements(By.cssSelector("div[class='field-set'] input[placeholder='1st']"));
if(!box1.isEmpty()) {
box1.get(0).sendKeys(value);
}
break;
case "pin2" :
List<WebElement> box2 = driver.findElements(By.cssSelector("div[class='field-set'] input[placeholder='2nd']"));
if(!box2.isEmpty()) {
box2.get(0).sendKeys(value);
}
break;
case "pin3" :
List<WebElement> box3 = driver.findElements(By.cssSelector("div[class='field-set'] input[placeholder='3rd']"));
if(!box3.isEmpty()) {
box3.get(0).sendKeys(value);
}
break;
case "pin4" :
List<WebElement> box4 = driver.findElements(By.cssSelector("div[class='field-set'] input[placeholder='4th']"));
if(!box4.isEmpty()) {
box4.get(0).sendKeys(value);
}
break;
default :
System.out.println("pincode textbox key not found");
break;
}
Этот код отправит пин-код в соответствующее текстовое поле для пин-кода, если оно доступно на веб-странице.