2016-11-16 64 views
0

我在点击模式对话框中的按钮时有点麻烦。我在网上搜索,但似乎让我感到困惑(可能)或其他解决方案没有在我的具体情况下工作。在模态对话框中定位特定按钮的难点 - Selenium

使用情况如下:

  1. 在默认内容页我上的图标点击图像插入一个文本编辑器。

  2. 模式对话框弹出,我点击的上传按钮

  3. Windows文件导航打开,我粘贴文件路径为“文件名” textinputbox并确认提交。 Windows文件navigatr然后关闭

  4. 与上传的文件名中的模式对话框更新和我点击“添加”按钮

  5. 一个新窗口弹出,我通过勾选复选框,然后点击一个确认一些进一步的细节确定按钮

  6. 弹出窗口消失,步骤2和步骤4中的模态对话框消失或更改为新模式对话框,警告我存在重复文件以及是“更新”还是“取消”。我想按此更新按钮。

我正在这最后的最后一步。我只是不能找到这个按钮。也许这只是漫长的一天,我现在太累了。所以,在我开始敲响桌子之前,我会感激不尽的帮助。

的HTML如下:

<div class="d2l-dialog" style="top: 318px; width: 400px; height: 420px; left: 680px; z-index: 1008;"> 
<div class="d2l-dialog-inner" style="height: 418px;"> 
<iframe class="d2l-dialog-frame" src="/d2l/lp/fileinput/6606/Duplicates?files=photo.jpg" name="d2l_c_1_783" allowfullscreen="" scrolling="no" style="width: 398px; height: 418px; overflow: hidden;" frameborder="0"> 
<!DOCTYPE html> 
<html data-lang-default="en-GB" lang="en-GB"> 
<head> 
<body class="d2l-body d2l-typography vui-typography d2l-dialog-document-body" style="overflow: hidden;"> 
<div id="MathJax_Message" style="display: none;"></div> 
<div class="d2l-dialog-width d2l_1_0_132 d2l-dialog-flex" data-height="420" style="width: 398px;"> 
<div class="d2l-dialog-title d2l-dragdrop-draggable"> 
<div class="d2l-dialog-body" style="height: 336px;"> 
<div class="d2l-dialog-footer-container"> 
<div class="d2l-dialog-footer"> 
<div class="d2l-dialog-buttons"> 
<div class="d2l-dialog-button-group"> 
<a id="d2l_1_2_435" class="vui-button d2l-button vui-button-primary" role="button" tabindex="0" aria-disabled="false">Update</a> 
<a id="d2l_1_3_576" class="vui-button d2l-button" role="button" tabindex="0" aria-disabled="false">Cancel</a> 
<span tabindex="0"></span> 
</div> 
<div class="d2l-clear"></div> 
</div> 
<span class="d2l-dialog-resize"></span> 
</div> 
</div> 
</div> 
<script type="text/javascript" src="https://s.brightspace.com/lib/jquery/1.11.0/jquery.min.js"> 
<script type="text/javascript" src="https://s.brightspace.com/lib/jqueryui/1.10.3/jquery-ui.min.js"> 
<script type="text/javascript" src="https://s.brightspace.com/lib/bsi/10.6.2-4/bsi.min.js"> 
<script type="text/javascript" src="/d2l/common/assets/tock/tock.min.js?v=10.6.7.4465-92"> 

这是我的尝试之一:

Thread.sleep(1000); 
driver.switchTo().activeElement(); 
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@name, 'd2l_c_1_')]"))); 
driver.findElement(By.xpath("//a[starts-with(@id,'d2l_1_2_']")).click(); 

超时就行:

driver.switchTo().activeElement(); 

我试着删除这个,但它不起作用。一些援助将不胜感激。

回答

0

我解决了我的问题,这是我犯的一个愚蠢的错误。在上面的步骤5中,我忘记了更改回原始窗口,然后搜索iframe,代码本身在修改后基本没问题。

npc.get_window_ids(); 
driver.switchTo().window(npc.getWindow2()); 
driver.manage().window().maximize(); 

//click add 
driver.findElement(By.xpath("//input[@type='checkbox']")).click(); 
driver.findElement(By.xpath(".//*[@id='d2l_form']/div[2]/div[1]/table[2]/tbody/tr/td[1]/a")).click(); 

Thread.sleep(1000); 
//forgot to add this line DOH! 
driver.switchTo().window(npc.getWindow1()); 
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@name, 'd2l_c_1_')]"))); 
driver.findElement(By.xpath("//a[starts-with(@id,'d2l_1_2_')]")).click(); 
相关问题