我有点想要点击模态对话框中的按钮。我在网上搜索,但似乎要么让我自己感到困惑(可能),或者其他解决方案在我的具体情况下无效。
用例如下:
在默认内容页面中,我点击图标将图像插入文本编辑器。
弹出模态对话框,然后点击上传按钮
打开Windows文件导航器,然后将文件路径粘贴到“文件名”textinputbox中并确认提交。然后Windows文件navigatr关闭
模态对话框使用上传的文件名更新,然后点击“添加”按钮
弹出一个新窗口,我通过选中一个复选框并单击确定按钮来确认更多详细信息
弹出窗口消失,步骤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 :(得分: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();