我们在Tab1部分和Tab2部分有两个名为“Inschrijven”的按钮,如下图所示 elasticserch documentation
Tab 1:
<span class="form-submit-wrapper"><input type="submit" id="edit-submit--3" name="op" value="Inschrijven" class="form-submit"></span>
Tab 2:
<span class="form-submit-wrapper"><input onclick="return validate_course_anywhere(this)" type="submit" id="edit-submit--22" name="op" value="Inschrijven" class="form-submit"></span>
When I click element with id "edit-submit--3"
这个behat代码场景在标签1部分中有效,但在标签2部分(When I click element with id "edit-submit--22"
)
/**
* @When /^I click element with id "([^"]*)"$/
*/
public function iClickElementWithId($class) {
$locator = "#$class";
$element = $this->getSession()->getPage()->find('css', $locator);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS selector: "%s"', $locator));
}
$element->click();
$this->getSession()->wait(1000);
}
但是标签2部分显示错误消息:
Exception thrown by (//html/descendant-or-self::*[@id = 'edit-submit--22'])[1]
Element is not clickable at point (813.5, 16.666671752929688). Other element would receive the click: <a href="/certificering" title="" class="menu__link"></a>
答案 0 :(得分:0)
It seems that the selector is ok, the issue here is that is not clickable and some other element is in the front of it and receives the click.
Some of the possible issues: 1. wait for the element to be visible 2. you have 2 elements with the same id and the first one is found but not clickable 3. wait for the page to be loaded if needed
To use the onClick attribute you can use a css selector like: [onclick*='some_value_from_attribute']
You should have a method to click by selector and not particular method for just one attribute.
Another thing to avoid is using blind waits, you should try to use conditional waits.