1
我奮力處理彈出(查找)窗口,當我點擊一個IMG圖標如何使用Selenium彈出窗口的webdriver
守則,顯示輸入值:
String parentHandle = LoginPage2.driver.getWindowHandle();
LoginPage2.driver.findElement(By.id("opp4_lkwgt")).click();
//after you have pop ups
Set s = LoginPage2.driver.getWindowHandles();
Iterator ite=s.iterator();
while(ite.hasNext())
{
String popupHandle=ite.next().toString();
if(!popupHandle.contains(parentHandle))
{
LoginPage2.driver.switchTo().window(popupHandle);
//here you can perform operation in pop-up window**
TimeUnit.SECONDS.sleep(8);
LoginPage2.driver.findElement(By.id("lksrch")).sendKeys("sss");
//After finished your operation in pop-up just select the main window again
LoginPage2.driver.switchTo().window(parentHandle);
LoginPage2.driver.close();
}
}
我代碼不會集中到「查找」彈出窗口,並且我無法在「搜索」字段中輸入sss
。
HTML的查詢窗口:
<div class="pBody">
<div class="message infoM4" id="msgBox">
<table class="messageTable" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td>
<img src="/s.gif" alt="Information" class="msgIcon" title="Information">
</td>
<td class="messageCell"><div class="messageText">Opportunities cannot go against a Global Parent. Please select an Organisation that is lower in the hierarchy than a Global Parent.</div></td></tr>
</tbody></table></div><*script type="text/javascript">if (window.sfdcPage) sfdcPage.registerMessage('msgBox');</script>
<label for="lksrch">Search</label>
<input id="lksrch" maxlength="80" name="lksrch" size="20" type="text" value="">
<input value=" Go! " class="btn" name="go" title="Go!" type="submit">
<input value=" New " class="btn" name="new" onclick="javascript:top.resultsFrame.location='LookupResultsFrame?lktp=001&lkfm=editPage&lknm=opp4&lksrch=&lknew=1&lkent=006&lkfield=Account&igdp=0'" title="New" type="button">
<div class="bDescription"></div></div>
我面臨同樣的問題,弄來解決方法? – sbose