在我的应用程序中,我必须在文本字段中输入一些值。此文本字段包含一些默认值,因此首先我需要删除该值,然后键入新值,但既不能删除该值,也不能键入新值。任何帮助将非常感激。我试过以下代码:
WebElement samount=d1.findElement(By.id("ctl00_ContentPlaceHolder1_txtAmt"));
System.out.println(samount);
samount.clear();
samount.sendKeys("100");
我也试过这个:
WebElement searchField=d1.findElement(By.id("ctl00_ContentPlaceHolder1_txtAmt"));
System.out.println(searchField);
searchField.click();
searchField.clear();
searchField.sendKeys(Keys.BACK_SPACE );
searchField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
searchField.sendKeys(Keys.DELETE);
searchField.sendKeys("100");
searchField.click();
以下是我的页面的 HTML:
<table cellspacing="6" cellpadding="6" style="width: 100%;">
<tbody>
<tr>
<tr>
<td style="text-align: center;" colspan="2">
<br>
<table width="100%" style="text-align: center;">
<tbody>
<tr>
<tr>
<td id="ctl00_ContentPlaceHolder1_tdFirst" style="width:35%;"> </td>
<td style="text-align: right;">
<td style="text-align: left;">
<input id="ctl00_ContentPlaceHolder1_txtAmt" class="txtAlpha" type="text" style="width:100px;" onblur="checkSender();" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;AmountOnly();" onchange="javascript:setTimeout('__doPostBack (\'ctl00$ContentPlaceHolder1$txtSenderAmt\',\' \')', 0)" maxlength="10" value="0.00" name="ctl00$ContentPlaceHolder1$txtSenderAmt">