2011-10-27 11 views
7

iframe内のスパンのxpath式を取得する必要があります。 Iframeのポップアップ内にspanのXPath式を取得する際のヘルプが必要です。Iframeポップアップ内にspanのXPath式を取得する際のヘルプが必要

私はIFRAMEを得ることができますが、IFRAME内/ HTML /体を得ることが任意の助けを起きていない。これは、いくつかの点で、すべてのスパン要素を選択します

<div class="gwt-PopupPanelGlass" style="position: absolute; left: 0px; top: 0px; visibility: visible; display: block; width: 1680px; height: 222px;"></div> 
<div class="gwt-PopupPanel" style="left: 439px; top: 0px; visibility: visible; position: absolute; overflow: visible;"> 
<div class="popupContent"> 
<div class="ph-PopupDialog" style="position: relative; width: 800px; height: 220px;"> 
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex;">&nbsp;</div> 
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex;">&nbsp;</div> 
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 32px;"> 
<div style="position: absolute; overflow: hidden; left: 0px; top: 32px; right: 0px; bottom: 0px;"> 
<div class="ph-PopupDialog-content" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex;">&nbsp;</div> 
<div style="position: absolute; overflow: hidden; left: 5px; top: 5px; right: 5px; bottom: 5px;"> 
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div> 
<iframe class="gwt-Frame ph-PaymentFrame" name="paymentFrame" src="javascript:''"> 
<html> 
<head> 
<body onload="pageLoaded();"> 
<div class="ph-View"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="grid_12"> 
<div class="ph-ButtonPanel ph-ButtonPanel-undecorated"> 
<a class="ph-Button ph-Button-button" onclick="submit();return false;" style="float: right; margin-left: 5px;" href="#"> 
<a class="ph-Button ph-Button-button" onclick="cancel();return false;" style="float: right; margin-left: 5px;" href="#"> 
<span>Cancel</span> 
</a> 
</div> 
</div> 
</div> 
</div> 
</body> 

`

答えて

1

使用

//iframe//span 

これは、XML文書内の任意のiframe要素の子孫であるすべてのspanの要素を選択します。

0
//span [ancestor::iframe] 

をいただければ幸いです祖先iframe要素を持つ

8

iframe内の要素は、実際には別のページにあります。 iframeのsrc値の値であるページのアドレスを見つけて読み込み、そのページの要素にアクセスする必要があります。

5

あなたは、IFRAMEのcontentDocumentプロパティにするXPathの範囲を設定する必要があります。

var iframe = document.getElementsByTagName("iframe")[0]; 
var theFirstSpan = document.evaluate('//span', iframe.contentDocument, 
     null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue 
-1

我々が直接iframe内の要素にアクセスすることはできません。私たちは最初にiframeにswithする必要があります。

私はPHP Facebook webdriverを使用していますが、これは私にとってはまったく機能しています。

$driver->get("http://www.example.com"); // containing an iframe 
$iFrame = $driver->findElement(
      WebDriverBy::xpath('//iframe[@name="iFrameName"]') //name or id or whatever by which we can access. 
     ); 
$driver->switchTo()->frame($iFrame); 

今、私たちは、私はこれが誰かを助けることを願ってい

$spanButton = $driver->findElement(
      WebDriverBy::xpath('//span') 
     ); 

をとしてそのspanにアクセスすることができます!

関連する問題