对于iframe,我有这样的HTML代码:
<iframe class="class1" prio="0" title="Details" type="detail" source="/something/somepage.aspx" style="display:none" frameborder="0"></iframe>
Run Code Online (Sandbox Code Playgroud)
这个框架有一个菜单,文本输入和里面的按钮,因为它在当前页面上打开一个弹出窗口.Popup从源页面获取其数据,如上所述.
我尝试了不同的方法,即通过手动查找iframe的索引,然后显示其标题,看看我是否在正确的框架但没有运气.
我试图在iframe中的表单中键入数据,然后返回到主页但是我一无所知.请帮忙!
Yi *_*eng 14
SwitchTo() 方法采用索引,名称或框架元素,因此您可以尝试使用名称或框架元素.
//find the frame by class/title/type/source
IWebElement detailFrame = driver.FindElement(By.XPath("//iframe[@class='class1']"));
driver.SwitchTo().Frame(detailFrame);
//alternatively, find the frame first, then use GetAttribute() to get frame name
IWebElement detailFrame = driver.FindElement(By.XPath("//iframe[@class='class1']"));
driver.SwitchTo().Frame(detailFrame.GetAttribute("name"));
//you are now in iframe "Details", then find the elements you want in the frame now
IWebElement foo = driver.FindElement(By.Id("foo"));
foo.Click();
//switch back to main frame
driver.SwitchTo().DefaultContent();
Run Code Online (Sandbox Code Playgroud)
你试过(java代码):
driver.switchTo().frame("iFrameName");
driver.findElement(By.id("formOne")).click();
driver.findElement(By.id("formOne")).sendKeys("abc");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16775 次 |
| 最近记录: |