久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Selenium Web驅(qū)動(dòng)程序和Java。元素在(x,y)點(diǎn)處不可單擊。其他元素將獲得點(diǎn)擊?

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

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

1.由于存在JavaScript或AJAX調(diào)用而無法單擊元素

嘗試使用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.在元素可單擊之前,頁面正在刷新。

在這種情況下,請(qǐng)誘導(dǎo)ExplicitWait,即第4點(diǎn)中提到的webdriverwait。

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

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

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

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

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

用于JavascriptExecutor直接在元素上發(fā)送點(diǎn)擊。

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

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

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

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

@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);}

標(biāo)簽: java
主站蜘蛛池模板: 砚山县| 平原县| 郁南县| 吉木乃县| 呼伦贝尔市| 涞源县| 民县| 桐城市| 炉霍县| 慈利县| 张家界市| 宣汉县| 镇坪县| 阿合奇县| 华安县| 永新县| 友谊县| 彭阳县| 和田市| 海安县| 东丽区| 渑池县| 花莲县| 新津县| 屏南县| 大新县| 扎鲁特旗| 伊宁县| 阿拉善左旗| 秦皇岛市| 上蔡县| 普格县| 海淀区| 崇礼县| 金溪县| 景德镇市| 攀枝花市| 堆龙德庆县| 临泉县| 阿拉善右旗| 荣成市|