簡體   English   中英

無法訪問Selenium Webdriver Java中的UI對話框

[英]Unable to access UI dialog in Selenium webdriver java

我有一個iframe,然后是一個包含創建發票按鈕的小部件。 它不在iframe中,但不在iframe中,我無法訪問它。我無法使用selenium webdriver java訪問此對話框,我試圖使用java訪問創建發票按鈕:

</div><div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><div class="ui-dialog-buttonset"><button type="button" id="saveBtnDialog" class="btn btn--primary">Create Invoice</button><button type="button" id="CancelBtnDialog" class="btn btn--primary">Cancel</button></div></div></div>  

我的代碼:

 private final By createInvoiceBtn = By.id("saveBtnDialog");
 driver.switchTo().frame(driver.findElement(By.cssSelector(".ui-dialog-buttonset")));
 driver.findelement(createInvoiceBtn).click();

據我了解,如果您的button不在frame並且您已經在frame

您需要從frame切換到defaultContent ,然后找到element並執行以下操作:

//first switch to out side the frame
driver.switchTo().defaultContent();

//now implement WebDriverWait to provide wait
WebDriverWait wait = new WebDriverWait(driver, 100);

//wait until ExpectedConditions is not true
WebElement buttonEl = wait.until(ExpectedConditions.elementToBeClickable(By.id("saveBtnDialog")));

//now you go for the action
buttonEl.click(); 

希望對您有幫助... :)

暫無
暫無

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

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