[英]Unable to click the 'button' in selenium webdriver (using Java)
[英]Unable to click on this Button using selenium (java)
我有click();
問題click();
使用selenium webdriver 的功能。
這是 outputHtml :
<button type="button" class="k-button k-primary" tabindex="0" style="width: 50%;">Valider< /button>
我使用各種xpath
使用了findEelement
例如:
- "//button[@class = 'k-button k-primary' and @type = 'button']"
- "//*[contains(@class, 'k-button k-primary') and text()='Valider']"
並且仍然收到錯誤無法定位元素
這是我需要單擊的彈出窗口按鈕的屏幕截圖(按鈕驗證器)
您是否嘗試過實際復制和粘貼選擇器?
如果您使用的是 Windows 計算機:
在谷歌瀏覽器中按 F12 打開開發者窗口。
在 DOM 中找到您要查找的節點並右鍵單擊它。
然后去“復制”和“復制XPath”或者你可以“復制JS路徑”
然后您可以將路徑粘貼到您的代碼中並以這種方式嘗試。
在使用 selenium 進行開發時,我更喜歡使用 JS Path 選擇 dom 節點。
如果您遇到像您這樣的問題,“復制完整 XPath”選項在開發過程中很有用,因為它會從根節點復制完整路徑。
此功能適用於所有主要瀏覽器,但我最熟悉使用 Google Chrome 進行開發。
您確定 Element 在搜索時已加載嗎? 之前嘗試一個斷點並驗證它是否可用。
為了處理警報/彈出窗口,您需要切換到它
//switch to alert
Alert alert = driver.switchTo().alert();
//accept it
alert.accept();
// or accept it by your code
driver.findElement(By.XPATH("//button[@class = 'k-button k-primary' and @type = 'button']").click();
//dismiss alert
alert.dismiss();
//or dismiss with you code
driver.findElement(YOUR_LOCATOR).click();
//get text
String alertText = alert.getText()
請檢查彈出窗口是否在某個框架內。 如果是,那么你必須像這樣切換到框架 driver.switchTo.frame(iframe locator)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.