在Iframe弹出窗口中获取span的XPath表达式时需要帮助
Need Help in getting XPath expression for span inside an Iframe popup
需要在iframe中获取span的xpath表达式。在Iframe弹出窗口中获取span的XPath表达式时需要帮助。
我可以获取iframe,但在iframe中获取/html/body没有发生任何帮助,将不胜感激
<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;"> </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;"> </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;"> </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>
`
iframe中的元素实际上在另一个页面中。因此,您应该首先找到该页面的地址,即iframe的src值,然后加载它,然后访问该页面中的元素。
您需要将xpath的范围设置为iframe的contentDocument属性:
var iframe = document.getElementsByTagName("iframe")[0];
var theFirstSpan = document.evaluate('//span', iframe.contentDocument,
null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
使用:
//iframe//span
这将选择作为XML文档中任何iframe
元素的后代的每个span
元素。
//span [ancestor::iframe]
这将选择在某个点上具有祖先iframe元素的所有span元素。
我们不能直接访问iframe
中的元素。我们需要先切换到iframe。
我正在使用PHP Facebook网络驱动程序,这对我来说非常有效:
$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);
现在,我们可以访问span
作为:
$spanButton = $driver->findElement(
WebDriverBy::xpath('//span')
);
相关文章:
- 节点中带有空格的 XPath 表达式表示挑衅.js
- 将变量传递到CasperJS中的XPath表达式中
- 将param作为xpath表达式传递给XSLT-javascript
- PhantomJS文件上载无法使用XPath表达式
- 如何使用XPath表达式在CasperJS中检索元素的属性
- 重构 Xpath:同一父级下的多个表达式
- 在属性名称中搜索带有冒号的 xpath 表达式会引发异常(节点.js元素树模块)
- XPath 表达式,用于按源顺序选择 *所有* 元素、文本节点和注释节点
- 计算 XML 中的 XPath 表达式
- 获取与正则表达式匹配的 HTML 单词的 XPATH
- 将 XPath 表达式与 JavaScript 变量进行匹配
- 用于基于多个值解析XML的XPath表达式
- 正在Chrome中评估xpath表达式
- 以编程方式创建XPath表达式
- 什么'这个xpath表达式错了
- InvalidSelectorError:xpath表达式的结果是[object Text].它应该是一个元素
- 在Iframe弹出窗口中获取span的XPath表达式时需要帮助
- 在CasperJS中XPath表达式中使用contains(text(), "string")时如何
- 使用javascript在HTML中运行XPath表达式SVG
- 使用XPath表达式为Javascript添加自定义规则