Exception in thread “main“ org.openqa.selenium.ElementClickInterceptedException: element click inter

您所在的位置:网站首页 chrome版本太旧 Exception in thread “main“ org.openqa.selenium.ElementClickInterceptedException: element click inter

Exception in thread “main“ org.openqa.selenium.ElementClickInterceptedException: element click inter

2023-03-16 12:00| 来源: 网络整理| 查看: 265

运行环境:

Selenium+Java+maven

问题描述

错误提示:Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable at point (669, 35)

错误翻译:线程“main”中的异常 org.openqa.selenium.ElementClickInterceptedException: 元素单击被拦截: 元素在点 (669, 35) 处不可点击

错误简介:click失效

public class WebDriver常用方法 { public static void main(String[] args) throws InterruptedException { ChromeDriver driver = new ChromeDriver(); driver.get("https://www.baidu.com"); driver.manage().window().setSize(new Dimension(500,900)); WebElement bd_text = driver.findElement(By.cssSelector("#kw")); WebElement bd_button = driver.findElement(By.id("su")); //WebElement bd_button = driver.findElement(By.xpath("//span[@class='bg s_btn_wr']/input")); bd_text.sendKeys("java"); Thread.sleep(2000); bd_text.clear(); bd_text.sendKeys("python"); bd_button.click(); Thread.sleep(2000); driver.quit(); } } 原因分析:

因为我将Chrome窗口进行了缩放,在缩小之后,原界面中的button按钮不可见,导致程序无法通过定位找到元素值,无法用click点击从而报错。

解决方案:

1.将窗口调制最大

2.可以将driver.click改为driver.submit(),从而不需要进行点击就可以用类似于enter进行提交

3.也可以用driver.sendKeys(Keys.ENTER)实现回车功能进行

4.如果必要进行小窗口调试,则需要用dragAndDrop() 拖动鼠标事件拖动见面,然后在进行click()



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3