2016-03-05 3 views
0

Итак, я пытаюсь добавить псевдонимы электронной почты в свою учетную запись Gmail автоматически, и я написал этот код для переноса псевдонимов из списка в Gmail. Тем не менее, я столкнулся с проблемой поиска дескриптора окна.Переключение между окнами с селеном и firefox

Мой код:

 for (int p = 0; p < InstagramAievx.list.getItemCount(); p++) { 

     driver.findElement(By.cssSelector("span[role=link][class=sA][idlink='']")).click(); 
     TimeUnit.SECONDS.sleep(2); 
     handleMultipleWindows("Gmail - Add another email address you own"); 
     driver.findElement(By.id("cfn")).clear(); 
     driver.findElement(By.name("cfn")).sendKeys(InstagramAievx.gmailname.getText()); 
     driver.findElement(By.id("focus")).clear(); 
     driver.findElement(By.name("cfa")).sendKeys(InstagramAievx.list.getItem(m)); 
     if (driver.findElement(By.id("cfia")).isSelected()) { 
      driver.findElement(By.id("cfia")).click(); 
     } 
     ; 
     driver.findElement(By.cssSelector("css=[type=submit][value=Next Step »]")).click(); 

     m++; 
     handleMultipleWindows("Settings - " + InstagramAievx.email.getText() + "@gmail.com - Gmail"); 
    } 

} 

Метод handleMultipleWindows:

public void handleMultipleWindows(String windowTitle) { 
    Set<String> windows = driver.getWindowHandles(); 

    for (String window : windows) { 
     driver.switchTo().window(window); 
     if (driver.getTitle().contains(windowTitle)) { 
      return; 
     } 
    } 
} 

Ошибка:

org.openqa.selenium.NoSuchWindowException: Window not found. The browser window may have been closed. 
Command duration or timeout: 24 milliseconds 
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33' 
System info: host: 'ABJ-PC', ip: '192.168.1.4', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_74' 
Driver info: org.openqa.selenium.firefox.FirefoxDriver 
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=44.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] 
Session ID: 0482ba0b-052c-483a-90f5-2a4d4a55dcf2 
*** Element info: {Using=css selector, value=css=[type=submit][value=Next Step »]} 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:492) 
    at org.openqa.selenium.By$ByCssSelector.findElement(By.java:430) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355) 
    at com.example.tests.TestInstagram.Gmail(TestInstagram.java:247) 
    at com.example.tests.InstagramAievx$11.actionPerformed(InstagramAievx.java:304) 
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 
    at java.awt.Component.processMouseEvent(Component.java:6535) 
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) 
    at java.awt.Component.processEvent(Component.java:6300) 
    at java.awt.Container.processEvent(Container.java:2236) 
    at java.awt.Component.dispatchEventImpl(Component.java:4891) 
    at java.awt.Container.dispatchEventImpl(Container.java:2294) 
    at java.awt.Component.dispatchEvent(Component.java:4713) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) 
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525) 
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) 
    at java.awt.Container.dispatchEventImpl(Container.java:2280) 
    at java.awt.Window.dispatchEventImpl(Window.java:2750) 
    at java.awt.Component.dispatchEvent(Component.java:4713) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) 
    at java.awt.EventQueue.access$500(EventQueue.java:97) 
    at java.awt.EventQueue$3.run(EventQueue.java:709) 
    at java.awt.EventQueue$3.run(EventQueue.java:703) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) 
    at java.awt.EventQueue$4.run(EventQueue.java:731) 
    at java.awt.EventQueue$4.run(EventQueue.java:729) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 

Любая помощь? Благодарю.

ответ

0

Новое окно, на которое вы пытаетесь переключиться, - это на самом деле новая вкладка, а не новое окно. Вы можете переключиться на новую вкладку, используя этот метод в некоторых браузерах, но не в FireFox. Я предлагаю вам сделать это в Chrome.

+0

Я получаю ту же ошибку. Я не знаю, что вызывает это. @Guy – AAlzaabi

+0

@AAlzaabi Я отредактировал свой ответ. – Guy

Смежные вопросы