Selenium webdriver Behat/Mink-无法通过带有GouttDriver的xpath找到元素
我正在使用Behat 3.0和Mink 1.6 这些代码适用于Selenium2和Zombie,但不适用于Goutte:Selenium webdriver Behat/Mink-无法通过带有GouttDriver的xpath找到元素,selenium-webdriver,behat,mink,zombie.js,goutte,Selenium Webdriver,Behat,Mink,Zombie.js,Goutte,我正在使用Behat 3.0和Mink 1.6 这些代码适用于Selenium2和Zombie,但不适用于Goutte: $this->assertSession()->elementTextContains('xpath', "//div[@id='pagecontent-shop']/form/table/tbody/tr[12]/td[2]", $arg1); $page = $this->getSession()->getPage();
$this->assertSession()->elementTextContains('xpath', "//div[@id='pagecontent-shop']/form/table/tbody/tr[12]/td[2]", $arg1);
$page = $this->getSession()->getPage();
$element = $page->find('xpath', "//div[@id='pagecontent-shop']/form/table/tbody/tr[12]/td[2]",)->getText();
有人知道发生了什么吗?您是否尝试了findById()
e、 g
e、 g
编辑:
下面的示例遍历表中的输入
元素,并查找具有特定名称
的元素。不过你需要修改一下
/**
* @Given /^the table contains "([^"]*)"$/
*/
public function theTableContains($arg1)
{
$session = $this->getSession();
$element = $session->getPage()->findAll('css', 'input');
if (null === $element) {
throw new \Exception(sprintf('Could not evaluate find select table'));
}
$options = explode(',', $arg1);
$match = "element_name";
$found = 0;
foreach ($element as $inputs) {
if ($inputs->hasAttribute('name')) {
if (preg_match('/^'.$match.'(.*)/', $inputs->getAttribute('name')) !== false) {
if (in_array($inputs->getValue(), $options)) {
$found++;
}
}
}
}
if (intval($found) != intval(count($options))) {
throw new \Exception(sprintf('I only found %i element in the table', $found));
}
}
你好!您的解决方案会很好,但正如您所看到的,我的元素在一个表中,没有id。。。
/**
* Click on the element with the provided css id
*
* @Then /^I click on the element with id "([^"]*)"$/
*
* @param $elementId ID attribute of an element
* @throws \InvalidArgumentException
*/
public function clickElementWithGivenId($elementId)
{
$session = $this->getSession();
$page = $session->getPage();
$element = $page->find('css', '#' . $elementId);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS: "%s"', $elementId));
}
$element->click();
}
/**
* @Given /^the table contains "([^"]*)"$/
*/
public function theTableContains($arg1)
{
$session = $this->getSession();
$element = $session->getPage()->findAll('css', 'input');
if (null === $element) {
throw new \Exception(sprintf('Could not evaluate find select table'));
}
$options = explode(',', $arg1);
$match = "element_name";
$found = 0;
foreach ($element as $inputs) {
if ($inputs->hasAttribute('name')) {
if (preg_match('/^'.$match.'(.*)/', $inputs->getAttribute('name')) !== false) {
if (in_array($inputs->getValue(), $options)) {
$found++;
}
}
}
}
if (intval($found) != intval(count($options))) {
throw new \Exception(sprintf('I only found %i element in the table', $found));
}
}