請參見圖片以瞭解更多詳細信息::![我想輸入文本區域中的文本:照片中提到] [1] [1]:http://i.stack.imgur.com/sai92.png我想將文本輸入到文本區域,但發現該元素未找到時發生錯誤。我已經嘗試了X路徑,名稱和ID,但無法執行此代碼,並希望與網頁上出現的其他元素一起玩測試目的,但沒有什麼!我不知道它可以用java執行程序或切換窗口來處理(彈出)。下面提到的是java代碼。如何處理這種情況請詳細說明。Java Selenium-webdriver:將文本輸入到文本區域
Java代碼:
@Test
public void CreteLead() throws InterruptedException
{
WebElement _loginName =
driver.findElement(By.xpath(OR.getProperty("username")));
_loginName.sendKeys(OR.getProperty("loginId"));
WebElement _password =
driver.findElement(By.xpath(OR.getProperty("password")));
_password.sendKeys(OR.getProperty("loginPassword"));
WebElement _login =
driver.findElement(By.xpath(OR.getProperty("login")));
_login.click();
Thread.sleep(5000);
WebElement _New =
driver.findElement(By.xpath(OR.getProperty("New")));
_New.click();
Thread.sleep(10000);
driver.findElement(By.id("btnCreateCustomer")).click();
HTML代碼:
<table class="tbl_top_align" width="100%" cellspacing="3" cellpadding="0">
<tbody>
<tr>
<tr>
<tr>
<tr id="trBranch">
<tr id="trAssign">
<td> Assign To*: </td>
<td>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="font-weight: normal !important;">
<div
id="ctl00_CPHPageContents_ctl00_CPHPageContents_ddlAssignedToPanel"
class="RadAjaxPanel" style="display: block;"
>
<span id="RequiredFieldValidator1"
class="error_message" style="display:none;"
>* missing</span>
</td>
<td style="vertical-align: middle !important;">
<td style="vertical-align: middle !important;"> Referral </td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="padding: 4px 0 5px;"> Follow-up on: </td>
<td style="padding: 4px 0 5px;">
<a id="btnFollowUp"
href="javascript:__doPostBack('ctl00$CPHPageContents$btnFollowUp','')"
>Not Scheduled</a>
</td>
</tr>
<tr>
<td> Account: </td>
<td>
<span id="ctl00_CPHPageContents_txtAccount_wrapper"
class="riSingle RadInput RadInput_Default" style="width: 160px;">
</td>
</tr>
<tr>
<td> Value: </td>
<td>
<span id="ctl00_CPHPageContents_txtAccountValue_wrapper"
class="riSingle RadInput RadInput_Default" style="width: 125px;">
</td>
</tr>
<tr>
<td>Description*:</td>
<td>
<textarea id="txtInstructions" class="schedule_notes"
style="height: 95px; width: 294px !important;" cols="20" rows="2"
name="ctl00$CPHPageContents$txtInstructions"
/>
<span id="RequiredFieldValidator2" class="error_message"
style="display:none;">* missing</span>
</td>
</tr>
<tr>
</tbody>
</table>
<div class="action_buttons">
</div>
現在我有這段代碼,但無法找到元素並顯示窗口ID。 winHandleBefore = driver.getWindowHandles(); \t \t itrate = winHandleBefore.iterator(); \t \t win = itrate.next(); (「彈出」+贏); \t \t driver.switchTo()。window(win); \t \t \t \t driver.findElement(By.xpath(「// HTML /體/格[1] /形式/ DIV [3]/DIV /表/ tbody的/ TR [9]/TD [2]/textarea的「))的SendKeys(」 測試「); –