2 回答

TA貢獻1815條經驗 獲得超6個贊
它是 INPUT 字段,只需先清除輸入字段,然后為 sendKeys 提供值。請取唯一的名稱 attr,您的 ID attrs 不是唯一的。
WebElement ele=driver.findElement(By.name("quantity"));
ele.clear();
ele.sendKeys("2");

TA貢獻1831條經驗 獲得超9個贊
我查看了您嘗試訪問的網頁。您嘗試TTPStorePage通過定位器在類中訪問的微調器quantity具有動態 ID。每次加載頁面時它都會更改。您必須更改定位器策略。
嘗試使用以下定位器之一作為數量。
CSS選擇器:
By quantity = By.cssSelector("div.quantity > input");
XPath:
By quantity = By.xpath("//div[@class='quantity']/input");
此外,quantityItem您不需要 for 循環的 in 方法,因為您可以將值直接設置為您想要的值,sendKeys因為它是一個input元素。
嘗試這個
public void quantityItem() {
driver.findElement(quantity).clear();
driver.findElement(quantity).sendKeys("3");
//pressing up arrow twice would make the spinner value 3
}
舉報