Selenium+PHPunit:foreach 集合中的元素
我正在寻找一种使用 PHPunit 处理 Selenium 中的元素集合的方法。假设我有以下代码:
<div class="test">aaa</div>
<div class="test">bbb</div>
<div class="test">ccc</div>
我希望能够处理每个循环内的所有
元素,假设通过使用 根据其类选择元素//div[@class='test']
$divs = ... //
foreach ($divs as $div) {
// do something
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获取整个页面内容的函数是:- getHtmlSource()
因此,加载 HTML 的最终函数调用将类似于 ..
$dom->loadHTML($this->getHtmlSource());
The function to get the content of your entire page is :- getHtmlSource()
So your final function call to load HTML would be something like ..
$dom->loadHTML($this->getHtmlSource());
在 PHP 中,如果您想处理一些 HTML 数据,一个很好的解决方案是使用
DOMDocument
类 -- 这意味着能够通过其 //www.php.net/manual/en/domdocument.loadhtml.php" rel="nofollow noreferrer">DOMDocument::loadHTML()
方法。Loading your HTML with DOMDocument :
然后,您可以实例化
DOMXpath
对象:Which will allow you to extract data from the HTML, using XPath Queries, with [**`DOMXPath::query()`**][4] :
In PHP, if you want to work with some HTML data, a great solution is using the
DOMDocument
class -- which means being able to work with DOM methods -- via itsDOMDocument::loadHTML()
method.Loading your HTML with DOMDocument :
You can then instanciate a
DOMXpath
object :Which will allow you to extract data from the HTML, using XPath Queries, with [**`DOMXPath::query()`**][4] :