點擊Selenium 中被覆蓋層隱藏的元素
在基於Selenium 的自動化中,點擊被覆蓋層遮擋的元素可能是一個常見的挑戰。錯誤訊息「Element MyElement is not clickable at point (x, y)... Other element will receive the click」表示這種情況。
解決問題
要解決此問題,請考慮以下方法:
WebElement element = driver.findElement(By.id("id1")); Actions actions = new Actions(driver); actions.moveToElement(element).click().build().perform();
JavascriptExecutor jse1 = (JavascriptExecutor)driver; jse1.executeScript("scroll(250, 0)"); // if the element is on top. jse1.executeScript("scroll(0, 250)"); // if the element is at bottom.
Thread.sleep(500); // replace 500 with an appropriate timeout in milliseconds
WebDriverWait wait2 = new WebDriverWait(driver, 10); wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));
WebDriverWait wait3 = new WebDriverWait(driver, 10); wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
WebElement ele = driver.findElement(By.xpath("element_xpath")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele);
以上是如何點選 Selenium 中覆蓋層隱藏的元素?的詳細內容。更多資訊請關注PHP中文網其他相關文章!