1

嗨,基本上我正在尝试切换到一个弹出窗口,然后在该弹出窗口上按下一个按钮,但是从某个地方我得到了错误。

这是网页的示例

http://i42.photobucket.com/albums/e326/limpep/example.png

这是我的代码

 for (String handle : driver.getWindowHandles()) {
                                 driver.switchTo().window(handle);

                               }


                       WebElement clicksa  =
driver.findElement(By.id("ButtonCancle"));
                           clicksa.sendKeys(Keys.ENTER);
                           driver.switchTo().defaultContent();

我得到的错误

    Exception in thread "AWT-EventQueue-0" org.openqa.selenium.NoSuchElementException: Unable to find element by id using "Accept Address" (7)
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_21'
Driver info: driver.version: ie
    at org.openqa.selenium.ie.ErrorHandler.verifyErrorCode(ErrorHandler.java:38)
    at org.openqa.selenium.ie.Finder.handleErrorCode(Finder.java:252)
    at org.openqa.selenium.ie.Finder.findElementById(Finder.java:126)
    at org.openqa.selenium.By$1.findElement(By.java:66)
    at org.openqa.selenium.ie.Finder.findElement(Finder.java:240)
    at org.openqa.selenium.ie.InternetExplorerDriver.findElement(InternetExplorerDriver.java:297)
    at com.capscanWebServers.CRMTesting$2.actionPerformed(CRMTesting.java:112)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

亲切的问候

4

2 回答 2

3

首先,您可能没有切换到正确的窗口。您正在迭代所有窗口并切换到第一个可能是您的主窗口的窗口。

如果弹出窗口是在window.createPopup()那时创建的,您将无法切换到它 - Selenium 2 不支持此类窗口。实现它有一些进展 - 请参阅http://code.google.com/p/selenium /issues/detail?id=27

于 2010-10-21T11:41:28.520 回答
1

我注意到您要搜索的 id 是“ButtonCancle”。那里有一个拼写错误。您是否应该寻找“ButtonCancel”?

于 2010-10-21T00:16:59.567 回答