我正在嘗試在包含默認字符串的文本字段中輸入一個金額。該字段的 HTML:<div class="InputGroup"> <span class="InputGroup-context">$</span> <input autocomplete="off" class="Input InputGroup-input" id="amount" name="amount" type="text" maxlength="12" value="0.00"></div>當(dāng)嘗試向字段輸入文本時,它不會替換默認文本,而是將其附加到該字段中。我曾嘗試使用amount.clear()(數(shù)量是我調(diào)用的元素),但在運行它并發(fā)送密鑰后,它會引發(fā)以下異常:selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document正如您將在我當(dāng)前的代碼中看到的那樣,我還嘗試雙擊默認文本,但這無濟于事。這是我目前的代碼:ActionChains(driver).move_to_element(amount).click(amount).click(amount).perform()amount.send_keys(Keys.BACKSPACE)amount.send_keys('100')當(dāng)我期望 100 時,這會導(dǎo)致輸入字段為 0.00100。
1 回答

互換的青春
TA貢獻1797條經(jīng)驗 獲得超6個贊
某些基于 JS 的 Web 應(yīng)用程序可能無法正確清除輸入字段。
您可以嘗試使用 Actions 類完全單擊并清除字段。例如:
elem = driver.findElement(By.id("amount"))actions.move_to_element(elem).click().build().perform()actions.send_keys(Keys.BACKSPACE) .send_keys(Keys.BACKSPACE) .send_keys(Keys.BACKSPACE) .send_keys(Keys.BACKSPACE).build().perform()
添加回答
舉報
0/150
提交
取消