本文介绍了调试“元素在点”不可点击“错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 完整的错误信息显示为: '会接受点击'的元素位于所讨论的元素的一侧,而不是在它的顶部,并且不会与其重叠,也不会在页面中移动。 我尝试添加偏移量,但这也不起作用。该项目在显示的窗口中,不需要滚动。 这是由以下3种类型引起的: 1.该元素无法点击。 使用动作 通过操作: WebElement element = driver.findElement(By(element_path)); 操作actions = new Actions(driver); actions.moveToElement(element).click()。perform(); 通过JavascriptExecutor: JavascriptExecutor jse =(JavascriptExecutor)驱动程序; jse.executeScript(scroll(250,0)); //如果元素在顶部。 jse.executeScript(scroll(0,250)); //如果元素在底部。 或 JavascriptExecutor jse =(JavascriptExecutor)驱动程序; jse.executeScript(arguments [0] .scrollIntoView(),Webelement); 然后点击元素。 2.页面在点击元素前被刷新 为此,请让页面等待几秒钟。 p> 3。这个元素是可点击的,但是在它上面有一个微调器/覆盖层 下面的代码将等到覆盖图消失时为止。 b By loadingImage = By.id(loading image ID); WebDriverWait wait = new WebDriverWait(driver,timeOutInSeconds); wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage)); 然后点击元素。 I see this only in Chrome.The full error message reads:The element that 'would receive the click' is to the side of the element in question, not on top of it and not overlapping it, not moving around the page.I have tried adding an offset, but that does not work either. The item is on the displayed window without any need for scrolling. 解决方案 This is caused by following 3 types:1.The element is not visible to click.Use Actions or JavascriptExecutor for making it to click.By Actions:WebElement element = driver.findElement(By("element_path"));Actions actions = new Actions(driver);actions.moveToElement(element).click().perform();By JavascriptExecutor:JavascriptExecutor jse = (JavascriptExecutor)driver;jse.executeScript("scroll(250, 0)"); // if the element is on top.jse.executeScript("scroll(0, 250)"); // if the element is on bottom.orJavascriptExecutor jse = (JavascriptExecutor)driver;jse.executeScript("arguments[0].scrollIntoView()", Webelement);Then click on the element.2.The page is getting refreshed before it is clicking the element.For this, make the page to wait for few seconds.3. The element is clickable but there is a spinner/overlay on top of itThe below code will wait until the overlay disppearsBy loadingImage = By.id("loading image ID");WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));Then click on the element. 这篇关于调试“元素在点”不可点击“错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 01:51