![](/img/trans.png)
[英]How to perform some actions on each value from a drop down using selenium java?
[英]How to perform actions on child iFrame using Selenium?
我們如何在iFrame中的iFrame上執行操作?
HTML:
<div id="div1">
<iframe id="iframe1">
<div id="div2">
<iframe id="iframe2">
</iframe>
</div>
<div id="div3">
<iframe id="iframe3">
</iframe>
</div>
</iframe>
</div>
我需要對iframe2和iframe3執行操作。 嘗試使用以下代碼:
1. driver.switchTo().frame("iframe1.0.iframe2");
2. WebElement firstFrame = driver.findElement(By.id("iframe1"));
driver.switchTo().frame(firstFrame);
WebElement secondFrame = driver.findElement(By.id("iframe2"));
driver.switchTo().frame(secondFrame);
但無法解決問題。
請提出是否要遵循其他方法。
這樣嘗試
//switch the control to first frame
WebElement firstFrame = driver.findElement(By.id("iframe1"));
driver.switchTo().frame(firstFrame);
//switch the control to second frame
WebElement secondFrame = driver.findElement(By.id("iframe2"));
driver.switchTo().frame(secondFrame);
//Switch back the control to first frame before switch it to frame3
driver.switchTo().frame(firstFrame);
WebElement thirdFrame = driver.findElement(By.id("iframe3"));
driver.switchTo().frame(thirdFrame);
試試這個片段。
//Switch To parent frame "iframe1"
WebElement parentFrame = driver.findElement(By.id("iframe1"));
driver.switchTo.frame(parentFrame );
//Switch To first child frame "iframe2"
WebElement firstChildFrame = driver.findElement(By.id("iframe2"));
driver.switchTo.frame(firstChildFrame );
//Do some actions on iframe2
//Switch To Top (or) Parent frame by using
driver.switchTo().defaultContent();
//Switch To parent frame "iframe1"
WebElement parentFrame = driver.findElement(By.id("iframe1"));
driver.switchTo.frame(parentFrame );
//Switch To second child frame "iframe3"
WebElement secondChildFrame = driver.findElement(By.id("iframe3"));
driver.switchTo.frame(secondChildFrame);
有關選擇框架的更多詳細信息,請使用此http://darrellgrainger.blogspot.ca/2012/04/frames-and-webdriver.html 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.