我正在尝试在包含默认字符串的文本字段中输入一个金额。该字段的 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>当尝试向字段输入文本时,它不会替换默认文本,而是将其附加到该字段中。我曾尝试使用amount.clear()(数量是我调用的元素),但在运行它并发送密钥后,它会引发以下异常:selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document正如您将在我当前的代码中看到的那样,我还尝试双击默认文本,但这无济于事。这是我目前的代码:ActionChains(driver).move_to_element(amount).click(amount).click(amount).perform()amount.send_keys(Keys.BACKSPACE)amount.send_keys('100')当我期望 100 时,这会导致输入字段为 0.00100。
1 回答

互换的青春
TA贡献1797条经验 获得超6个赞
某些基于 JS 的 Web 应用程序可能无法正确清除输入字段。
您可以尝试使用 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
提交
取消