国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Selenium Web驅動程序和Java。元素在(x,y)點處不可單擊。其他元素將獲得點擊?

瀏覽:163日期:2024-04-14 11:55:24
如何解決Selenium Web驅動程序和Java。元素在(x,y)點處不可單擊。其他元素將獲得點擊??

你可以通過以下任一過程解決它們:

1.由于存在JavaScript或AJAX調用而無法單擊元素

嘗試使用ActionsClass:

WebElement element = driver.findElement(By.id('navigationPageButton'));Actions actions = new Actions(driver);actions.movetoElement(element).click().build().perform();2.由于元素不在視口中,因此無法單擊

嘗試用于JavascriptExecutor將元素帶入視口中:

WebElement myelement = driver.findElement(By.id('navigationPageButton'));JavascriptExecutor jse2 = (JavascriptExecutor)driver;jse2.executeScript('arguments[0].scrollIntoView()', myelement);3.在元素可單擊之前,頁面正在刷新。

在這種情況下,請誘導ExplicitWait,即第4點中提到的webdriverwait。

4.元素存在于DOM中,但不可單擊。

在這種情況下, 將ExplicitWaitExpectedConditions設置為,elementToBeClickable以使元素可單擊:

webdriverwait wait2 = new webdriverwait(driver, 10);wait2.until(ExpectedConditions.elementToBeClickable(By.id('navigationPageButton')));5.元素存在但具有臨時覆蓋。

在這種情況下,ExplicitWait使用 ExpectedConditions設置invisibilityOfElementLocated為可使Overlay不可見。

webdriverwait wait3 = new webdriverwait(driver, 10);wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath('ele_to_inv')));6.元素存在但具有永久覆蓋。

用于JavascriptExecutor直接在元素上發送點擊。

WebElement ele = driver.findElement(By.xpath('element_xpath'));JavascriptExecutor executor = (JavascriptExecutor)driver;executor.executeScript('arguments[0].click();', ele);解決方法 Selenium 單擊

我使用了明確的等待,并發出警告:

org.openqa.selenium.WebDriverException:元素在點(36,72)不可單擊。其他元素將獲得點擊:…命令持續時間或超時:393毫秒

如果我使用Thread.sleep(2000)我不會收到任何警告。

@Test(dataProvider = "menuData")public void Main(String btnMenu,String TitleResultPage,String Text) throws InterruptedException { WebDriverWait wait = new WebDriverWait(driver,10); driver.findElement(By.id("navigationPageButton")).click(); try { wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu))); } catch (Exception e) {System.out.println("Oh"); } driver.findElement(By.cssSelector(btnMenu)).click(); Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(),Text);}

標簽: java
主站蜘蛛池模板: 富蕴县| 伊吾县| 育儿| 资源县| 华池县| 乌拉特前旗| 济源市| 内乡县| 沂水县| 福建省| 蒙自县| 洛阳市| 炉霍县| 内丘县| 兰考县| 南江县| 察隅县| 边坝县| 乐东| 台南市| 绥德县| 崇仁县| 建德市| 甘孜县| 清河县| 鹿泉市| 三亚市| 通河县| 忻州市| 陆良县| 康保县| 江川县| 河北区| 新丰县| 阿荣旗| 紫阳县| 西畴县| 岑溪市| 全椒县| 宣恩县| 保定市|