当我试图找到iframe时我无法找到它,可以试着帮我吗?我试过
driver.findElement(By.xpath("//iframe[contains(@src,'RLCommonControls/LeftNavigation.aspx?navMenuHeight=887')]"));
但它不起作用。我收到这个错误:
org.openqa.selenium.NoSuchElementException:无法找到元素:{“method”:“xpath”,“selector”:“// iframe [contains(@ src,'RLCommonControls / LeftNavig ation.aspx?navMenuHeight = 887' )]“}
我的HTML:
<tr>
<td valign="top" style="width: 200px; height: 832px;" data-ig="x:897723063.1:adr:0" adr="0">
<div class="gradientExplorer igspl_Office2007BluePane" style="height: 832px; overflow: hidden; border-style: none; width: 200px;" clientid="RL_SplitterPane_Navigation" data-ig="x:897723063.2:mkr:c0" mkr="c0">
<iframe frameborder="0" style="width:100%;height:100%;" title="/RLCommonControls/LeftNavigation.aspx" scrolling="no" marginwidth="0" marginheight="0" src="/RLCommonControls/LeftNavigation.aspx?navMenuHeight=887"> <!DOCTYPE html>
<html>
<head id="Head1">
答案 0 :(得分:1)
你可以使用Xpath: -
//iframe[@src='/RLCommonControls/LeftNavigation.aspx?navMenuHeight=887']
OR
//iframe[@title='/RLCommonControls/LeftNavigation.aspx' and @src='/RLCommonControls/LeftNavigation.aspx?navMenuHeight=887']
或更具体
WebElement frameele =driver.findElement(By.xpath("ANY XPATH FROM ABOVE"));
driver.switchTo().frame(frameele);
如果你想切换到框架,你可以这样做: -
<a>
希望它会对你有所帮助:)。
答案 1 :(得分:0)
如果它是html中的第一帧,那么:
driver.switchTo().frame(0);