如果条目成功提交,我想计算星数。对于尚未提交的条目,也可能有明星。如果这些条目尚未提交,我想忽略这些条目,即使这些条目尚未提交。
这是我想要计算的代码:
<table>
<tr id="entry_row_25494">
<td>
<img id="star_span_25494" img="" <="" src="/images/yes_star.png" onclick="toggleStar(25494);">
</td>
<td>
<img title="Entry successfully submitted" alt="Entry successfully submitted" src="/images/greencirclecheck.png">
</td>
</tr>
<tr id="entry_row_25496">
<td>
<img id="star_span_25496" img="" <="" src="/images/yes_star.png" onclick="toggleStar(25496);">
</td>
<td></td>
</tr>
</table>
这就是我所拥有的:
$numOfStars = $this->getXpathCount("xpath=(//img[contains(@src, 'yes_star') and (contains(@src, 'greencirclecheck.png'))])")
这是我到目前为止在Selenium IDE中使用storeXpathCount
尝试过的//table//img[@src='/images/yes_star.png' and @src='/images/greencirclecheck.png']
//table/tbody/tr[*]/td[*]/img[contains(@src, 'yes_star.png')]/parent::*[contains(@src, 'greencirclecheck.png')]
//img[contains(@src, 'greencirclecheck.png')]/preceding::img[contains(@src, 'yes_star.png')]
xpath=(//img[contains(@src, 'yes_star.png')]//img[contains(@src, 'greencirclecheck.png')])
但那些不起作用
如果您需要我澄清而不是低估,请告诉我。我是Selenium和PHPUnit的新手,所以问题可能不太清楚。
答案 0 :(得分:0)
$counted = 0;
$countEntries = $this->getXpathCount("//img[contains(@id, 'star_span')]");
for($num = 1; $num <= $countEntries; $num ++) {
$entry = $this->getAttribute("//tr[contains(@id, 'entry_row')][".$num."]@id");
$newEntry = preg_replace("/[^0-9]/i", "", $entry);
if($this->isElementPresent("//tr[@id='entry_row_".$newEntry."']//img[contains(@src, 'yes_star.png')]") && $this->isElementPresent("//tr[@id='entry_row_".$newEntry."']//input[contains(@checked, 'checked')]") == true) {
$counted ++;
}
}