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

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

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

瀏覽:117日期:2024-05-06 17:06:30
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決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
主站蜘蛛池模板: 嫩江县| 贵溪市| 衡阳县| 阜新市| 绩溪县| 屯留县| 滨海县| 连江县| 广宁县| 荆门市| 山阴县| 新巴尔虎左旗| 南岸区| 望都县| 噶尔县| 东平县| 林芝县| 玉环县| 上林县| 清镇市| 稷山县| 葵青区| 双鸭山市| 偏关县| 双城市| 芒康县| 仲巴县| 钦州市| 永宁县| 新巴尔虎右旗| 镇赉县| 镇沅| 邳州市| 孙吴县| 马龙县| 浦城县| 秭归县| 饶河县| 洪洞县| 湖口县| 天柱县|