簡體   English   中英

在元素上執行的Selenium Java單擊不起作用

[英]Selenium Java click performed on element did not work

以下內容出現在我的測試自動化代碼中。 它報告已奏效,但沒有奏效。 我可以分解一下並找出原因嗎?

Actions actions = new Actions(driver);

actions.moveToElement(element).click().build().perform();

我已經找到了該元素,並測試了它是否可以顯示並單擊,並且將整個批次包裝在try / catch中以檢查錯誤(未報告錯誤)。

我認為問題在於'element.isDisplayed'函數給出了令人誤解的結果。

方法1-嘗試使用WebElement時直接單擊

WebElement one = driver.findElement(By.name("one"));
WebElement two = driver.findElement(By.name("two"));

Actions actions = new Actions(driver);
actions.click(one)
.click(two)
.build().perform();

方式2-嘗試跳過build() ,可將其與單擊/雙擊結合使用

WebElement sngClick= driver.findElement(By.name("sngClick"));
WebElement dblClick= driver.findElement(By.name("dblClick"));

Actions actions = new Actions(driver);
actions.moveToElement(sngClick).click().perform();
actions.moveToElement(dblClick).doubleClick().perform();

請通過JavaScriptExecutor檢查:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(WebElement));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM