【问题标题】:Unable to access UI dialog in Selenium webdriver java无法访问 Selenium webdriver java 中的 UI 对话框
【发布时间】:2016-10-07 23:44:12
【问题描述】:

我有一个 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();

【问题讨论】:

  • 你能分享你的java代码吗?你做了什么。
  • 我将它添加到顶部有什么想法可以做什么?

标签: java selenium-webdriver automation selenium-chromedriver


【解决方案1】:

据我了解,如果您的 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(); 

希望对你有所帮助...:)

【讨论】:

  • :( 不走运 org.openqa.selenium.TimeoutException: 等待元素可点击 30 秒后超时:By.id: saveBtnDialog
  • @gabe 你确定..这个按钮不在框架内??
  • 看到了吗?它在 iframe 之外,按钮位于表单上,但在 iframe 之外,我从未见过类似的东西。
  • 我明白了..我点击按钮然后我输入 driver.findElement(By.tagName("body")).sendKeys(Keys.ENTER);
  • 猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2012-05-22
    • 1970-01-01
    相关资源
    最近更新 更多