Selenium Webdriver - (Java) - working with HTML dialogs

我是研究僧i 提交于 2019-12-11 22:26:24

问题


Here is the situation:

  1. Click on Import file button (this action will upload a file).
  2. After file upload, then appears a popup (HTML popup). I used driver.switchTo().frame(1); to switch to that popup and click "Next" in that popup.
  3. Clicking Next will navigate user to second step in that popup. Click process commission button in that second step of popup.
  4. After clicking process commission button, then appears a new confirmation popup (HTML popup).
  5. I am not able to click yes in that confirmation popup.

I tried using:
driver.switchTo().frame(0); - did not work
driver.switchTo().frame(1); - did not work
driver.switchTo().frame(2); - did not work

Please suggest any solution.

<form id="Form1" enctype="multipart/form-data" action="ProcessCommission.aspx?i=2115&pn=Manage+Commission&j=2345&prn=Process+Commission" method="post">
<iframe scrolling="no" frameborder="0" src="javascript:'<html></html>';" style="position: fixed; width: 400px; height: 100px; left: 431px; top: 53px; background-color: rgb(255, 255, 255); z-index: 3003;" tabindex="-1">  
<div id="RadWindowWrapper_confirm1381733327500" class="RadWindow RadWindow_Windows7 rwNormalWindow rwTransparentWindow" style="width: 400px; height: 100px; position: absolute; transform: none; backface-visibility: visible; visibility: visible; left: 431px; top: 377px; z-index: 3003;" unselectable="on">  
<table class="rwTable" cellspacing="0" cellpadding="0" style="height: 51px;">  
<tbody>  
<tr class="rwTitleRow">  
<tr class="rwContentRow">  
<td class="rwCorner rwBodyLeft"> </td>
<td class="rwWindowContent" valign="top">  
<iframe frameborder="0" name="confirm1381733327500" src="javascript:'<html></html>';" style="width: 100%; height: 100%; border: 0px none; display: none;" tabindex="0">  
<div id="confirm1381733327500_content">  
<div class="rwDialogPopup">  
<div class="rwDialogText">  
<div>
<a class="rwPopupButton" href="javascript:void(0); "onclick="$find('confirm1381733327500').close(true);" tabindex="-1">
<span class="rwOuterSpan">  
<span class="rwInnerSpan">Yes</span>  
</span>
</a>  
<a class="rwPopupButton" href="javascript:void(0);" onclick="$find('confirm1381733327500').close(false);" tabindex="-1">  
<span class="rwOuterSpan">  
<span class="rwInnerSpan">No</span>  
</span>

回答1:


dr.SwitchTo().Frame(dr.FindElement(By.TagName("iframe")));
dr.SwitchTo().DefaultContent();
dr.FindElement(By.XPath("your stuff goes here").Click();
dr.SwitchTo().DefaultContent();//switch back to default content of original page



回答2:


Try this:

driver.switchto.frame(0)
driver.switchto.frame(confirm1381733327500)


来源:https://stackoverflow.com/questions/19354893/selenium-webdriver-java-working-with-html-dialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!