Selenium Exception: Element is not clickable at point (x, y). Other element would receive the click.

异常:

public void click(WebDriver driver, String className) throws Exception {
     
	WebElement element = findElement(driver, By.className(className));
	if (element == null) {
     
		return;
	}
	// 抛出异常
	element.click();
}

解决办法:

  1. 使用 org.openqa.selenium.interactions.Actions
    public void click(WebDriver driver, String className) throws Exception {
           
    	WebElement element = findElement(driver, By.className(className));
    	if (element == null) {
           
    		return;
    	}
    	Actions actions = new Actions(driver);
    	actions.moveToElement(buttonElement).click().build().perform();
    }
    
  2. 滚动元素到可视位置
    public void click(WebDriver driver, String className) throws Exception {
           
    	WebElement element = findElement(driver, By.className(className));
    	if (element == null) {
           
    		return;
    	}
    	JavascriptExecutor jse = (JavascriptExecutor) driver;
    	jse.executeScript("arguments[0].scrollIntoView()", element);
    	element.click();
    }
    
  3. 直接执行 js 的点击事件
    public void click(WebDriver driver, String className) throws Exception {
           
    	WebElement element = findElement(driver, By.className(className));
    	if (element == null) {
           
    		return;
    	}
    	JavascriptExecutor jse = (JavascriptExecutor) driver;
    	jse.executeScript("arguments[0].click();", element);
    }
    

参考

你可能感兴趣的:(Java,selenium,java,test,webdriver)