我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。
WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
OR
元素是不可点击的,因为它上面有一个旋转/覆盖:
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
OR
Point p= element.getLocation();
Actions actions = new Actions(driver);
actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();
OR
如果仍然不能工作,请使用JavascriptExecutor
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", firstbutton);
其他回答
ruby / watir-webdriver /铬
我用了下面的技巧,看起来很管用:
#scroll to myelement
@browser.execute_script "window.scrollTo(#{myelement.element.wd.location[0]},#{myelement.element.wd.location[1]})"
# click myelement
myelement.when_present.fire_event("click")
而不是
webdriver.findElement(By.id("id1")).click();
试着使用
click(By.id("id1"));
void click(final By byLocator) {
waitFor(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
WebElement element = driver.findElement(byLocator);
if (element.isDisplayed()) {
try {
element.click();
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
@Override
public String toString() {
return "Element located " + byLocator + " clicked";
}
});
}
在Drupal中使用Selenium时:
// Get element.
$element = $this->driver->getElement('xpath=//input');
// Get screen location.
$location = $element->getLocation();
// To make sure that Chrome correctly handles clicking on the elements
// outside of the screen, we must move the cursor to the element's location.
$this->driver->moveCursor($location['x'], $location['y']);
// Optionally, set some sleep time (0.5 sec in the example below) if your
// elements are visible after some animation.
time_nanosleep(0, 500000000);
// Click on the element.
$element->click();
在我的例子中,它在Firefox中运行正常,但在Chrome中失败了。在Chrome中,在更新Chrome驱动程序版本到最新版本后,该问题得到了修复。
我做了一种蛮力点击,它对我有用。
try:
elem.click()
except:
print "failed to click"
size = elem.size
mid_of_y = int(size["height"])/2
stepts_to_do_to_left = int(size["width"])
while stepts_to_do_to_left > 0:
try:
print stepts_to_do_to_left, mid_of_y
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(elem, mid_of_y, stepts_to_do_to_left)
action.click()
action.perform()
print "DONE CLICK"
break
except:
pass