我需要在java中使用selenium API获取iframe的全部内容。
这是预期的结果:
<div id="WIN_0_304255502" arid="304255502" artype="View" ardbn="z2VF_02"
arcontainerid="304255802" arpercentwidth="100"
arpercentheight="100" class="arfid304255502 ardbnz2VF_02"
ardcf="1" style="top: auto; left: auto; width: 1318px;
height: 744px; z-index: 1135; min-width: 20px;
max-width: 32767px; min-height: 20px;
max-height: 32767px; position: relative; overflow: hidden;
background-color: transparent;"
arvfframe="<iframe style="top:0px&#59; left:0px&#59; width:1170px&#59;
height:744px&#59;
background-color: transparent&#59;" name="VF304255502" frameborder=0
scrolling="no"
allowtransparency="true" arviewbordercolor="null" title="z2VF_02" src="javascript:&quot;&lt;HTML&gt;&lt;/HTML&gt;&quot;"
onload="DVFol&#40;&#41;">
</iframe>
" arwindowid="0" arstop="1">
//more elements
现在我试试:
WebDriver driver= new HtmlUnitDriver();
driver.get(url3);
saveFile(driver.getPageSource());
运行程序后,我得到的结果不是我的预期。也许是因为存在iframe。
结果:
<div id="WIN_0_304255502" arid="304255502" artype="View" ardbn="z2VF_02" arcontainerid="304255802"
arpercentwidth="100" arpercentheight="100" class="arfid304255502 ardbnz2VF_02"
ardcf="1" style="top:0px; left:0px; width:1170px; height:744px;z-index:1135;background-color:transparent;min-width:20px;max-width:32767px;min-height:20px;max-height:32767px;"
arvfframe="<iframe style="top:0px&#59; left:0px&#59; width:1170px&#59;
height:744px&#59;background-color: transparent&#59;" name="VF304255502"
frameborder=0 scrolling="no" allowtransparency="true" arviewbordercolor="null"
title="z2VF_02" src="javascript:&quot;&lt;HTML&gt;&lt;/HTML&gt;&quot;"
onload="DVFol&#40;&#41;">
</iframe>
">
</div>
我也尝试访问iframe(driver.switchTo().frame(driver.findElement(By.name("VF304255503")
),但发生异常(org.openqa.selenium.NoSuchElementException: Unable to locate element with name: VF304255503
)。