【问题标题】:driver.findElement() with iframe and elements without IDdriver.findElement() 带有 iframe 和没有 ID 的元素
【发布时间】:2012-11-30 02:42:33
【问题描述】:

Java 代码:

driver.switchTo().frame(0);
                WebElement elemText = driver.findElement(By.xpath("/html/body[contains(@class='forum')]"));
                //WebElement elemText = driver.findElement(By.xpath("//td[@id='cke_contents_vB_Editor_001_editor']/textarea"));
                elemText.sendKeys(message);
                elemText.submit();
                forumLink =  driver.getCurrentUrl();

HTML 代码:

<td id="cke_contents_vB_Editor_001_editor" class="cke_contents" style="height:1726px" role="presentation">
<iframe style="width:100%;height:100%" frameborder="0" title="Rich text editor, vB_Editor_001_editor, press ALT 0 for help." src="" tabindex="-1" allowtransparency="true">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html dir="ltr" lang="en" contenteditable="true">
<head>
<title data-cke-title="Rich text editor, vB_Editor_001_editor, press ALT 0 for help.">Rich text editor, vB_Editor_001_editor, press ALT 0 for help.</title>
<base href="http://fairplay.garena.com/" data-cke-temp="1">
<link type="text/css" rel="stylesheet" href="http://fairplay.garena.com/clientscript/vbulletin_css/style00008l/editor_contents.css">

<style type="text/css" data-cke-temp="1">
form{border: 1px dotted #FF0000;padding: 2px;}

img.cke_hidden{background-image: url(http://fairplay.garena.com/clientscript/ckeditor/plugins/forms/images/hiddenfield.gif?t=B37D54V);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 16px !important;height: 16px !important;}
img.cke_iframe{background-image: url(http://fairplay.garena.com/clientscript/ckeditor/plugins/iframe/images/placeholder.png?t=B37D54V);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 80px;height: 80px;}
img.cke_anchor{background-image: url(http://fairplay.garena.com/clientscript/ckeplugins/vblink/images/anchor.gif?t=B37D54V);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 18px !important;height: 18px !important;}
a.cke_anchor{background-image: url(http://fairplay.garena.com/clientscript/ckeplugins/vblink/images/anchor.gif?t=B37D54V);background-position: left center;background-repeat: no-repeat;border: 1px solid #a9a9a9;padding-left: 18px;}
</style>
</head>
<body class="forum" spellcheck="true">
</body>
</html>
</iframe>
</td>

图片:http://s9.postimage.org/nwyvq3san/Screen_Shot038.jpg

我找不到在 iframe 中获取元素且没有 id 的方法。

你能帮帮我吗?

【问题讨论】:

    标签: java xpath selenium webdriver


    【解决方案1】:
    driver.switchTo().frame(driver.findElementByXpath("//iframe"));
    WebElement elemText = driver.findElement(By.xpath("//body[@class='forum')]"));
    

    应该可以。

    【讨论】:

    • org.openqa.selenium.NoSuchFrameException:无法定位帧://iframe 命令持续时间或超时:15 毫秒构建信息:版本:'2.24.1',修订:'17205',时间: '2012-06-19 15:28:49' 系统信息:os.name:'Windows 2003',os.arch:'x86',os.version:'5.2',java.version:'1.7.0_09'驱动信息:driver.version:RemoteWebDriver
    猜你喜欢
    • 1970-01-01
    • 2013-09-03
    • 2016-01-02
    • 2016-08-06
    • 1970-01-01
    • 2010-09-18
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多