使用 Selenium 确定是否选中特定类的复选框
我正在使用 Selenium 和 PHPUnit 来尝试判断是否选中了一堆具有特定类的复选框,但我遇到了一些麻烦。
我的代码:
$count = $this->getXpathCount('//form//input[@type="checkbox" and @class="required"]');
for ($i = 1; $i <= $count; $i++) {
$this->assertTrue($this->isChecked(sprintf('xpath=//form//input[@type="checkbox" and @class="required"][%d]', $i)));
}
不幸的是,我似乎不能在同一个标签上使用方括号两次,但我确实需要确保所有具有“required”类的复选框都被选中。
有什么建议吗?
I'm using Selenium with PHPUnit to try to tell whether a bunch of checkboxes with a specific class are checked and I'm having a bit of trouble.
My code:
$count = $this->getXpathCount('//form//input[@type="checkbox" and @class="required"]');
for ($i = 1; $i <= $count; $i++) {
$this->assertTrue($this->isChecked(sprintf('xpath=//form//input[@type="checkbox" and @class="required"][%d]', $i)));
}
Unfortunately, it doesn't seem like I can use square brackets twice on the same tag, but I do need to make sure all checkboxes that have the class "required" are checked.
Any Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不了解 Selenium,但是
DOMXPath->evaluate
会理解这种语法&返回一个浮点数(不是 int,但是嘿),也许它适合你:或者也许是一个简单的:
I don't know about Selenium, but a
DOMXPath->evaluate
would understand this syntax & return a float (not int, but hey), maybe it works for you:Or perhaps a simple:
除非我误会,否则两次使用方括号应该不会有任何问题。我能够使用 PHPUnit 和 Selenium 针对下面的 html 让您的代码顺利运行:
您是否正在运行最新版本的 PHPUnit 和 Selenium-rc?
Unless I'm misunderstanding, you shouldn't have any problems using square brackets twice. I was able to get your code to work without trouble using PHPUnit and Selenium against the html below:
Are you running the most recent version of PHPUnit and Selenium-rc?
$checkbox3 = $this->byClassName('required');
$this->assertTrue($checkbox3->selected());
$checkbox3 = $this->byClassName('required');
$this->assertTrue($checkbox3->selected());