无法在关闭窗口中找到元素.server没有提供堆栈跟踪信息

时间:2017-08-05 07:44:11

标签: selenium-webdriver

我使用java语言编写了一个selenium程序的代码。当我运行代码时遇到问题。我用过xpath&用于标识元素的linktext。程序代码也与youtube中的代码完全匹配。但仍然应用程序抛出如下错误消息。

Started InternetExplorerDriver server (64-bit)
3.4.0.0
Listening on port 15205
Only local connections are allowed
Aug 05, 2017 3:20:01 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 29 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'LAPTOP-5KIPBQVM', ip: '192.168.0.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{se:ieOptions={browserAttachTimeout=0.0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000.0, ie.useLegacyFileUploadDialogHandling=false, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0.0, ie.browserCommandLineSwitches=, requireWindowFocus=false, initialBrowserUrl=http://localhost:15205/, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, version=11, platform=WINDOWS, unexpectedAlertBehaviour=dismiss}]
Session ID: 7d81aaf4-8640-4c8a-829b-22efc698cb87
*** Element info: {Using=xpath, value=.//*[@id='adminAppMenu']/div[1]/ul/li[1]/a}
    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:215)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:509)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402)
    at AdminInterface.main(AdminInterface.java:40)

我的代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class AdminInterface {
    public static WebDriver driver;
    public void launchApplication()
    {
        System.setProperty("webdriver.ie.driver", "C:\\Users\\rprem\\Downloads\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();
        driver.get("http://www.gcrit.com/build3/admin/login.php?osCAdminID=es8t35f3gvo51onj3q1omnef00");
    }
    public void loginApplication(String Username, String Password) throws InterruptedException
    {
        driver.findElement(By.name("username")).sendKeys(Username);
        driver.findElement(By.name("password")).sendKeys(Password);
        driver.findElement(By.id("tdb1")).click();
        Thread.sleep(1000);
    }
    public void closeBrowser()
    {
        driver.close();
    }
public static void main(String[] args) throws InterruptedException 
    {
        AdminInterface obj = new AdminInterface();
obj.launchApplication();
        obj.loginApplication("admin", "admin@123");
        boolean Aol = driver.findElement(By.xpath(".//*[@id='adminAppMenu']/div[1]/ul/li[1]/a")).isDisplayed();
        Thread.sleep(1000);
        boolean Bol = driver.findElement(By.xpath(".//*[@id='adminAppMenu']/div[1]/ul/li[2]/a")).isDisplayed();
        Thread.sleep(1000);
        boolean Col = driver.findElement(By.xpath(".//*[@id='adminAppMenu']/div[1]/ul/li[3]/a")).isDisplayed();
        Thread.sleep(1000);
        if (Aol == true && Bol == true && Col == true)
        {
            System.out.println("TestCase 3: + All required links are present");
        }
        obj.closeBrowser();
    }
    }

1 个答案:

答案 0 :(得分:0)

以下是验证是否显示所有3个链接(即Categories/ProductsManufacturersReviews链接的示例代码块:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Q45519546_find_element 
{

    public static WebDriver driver;
    public void launchApplication()
    {
    System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
    driver = new InternetExplorerDriver();
    driver.get("http://www.gcrit.com/build3/admin/login.php?osCAdminID=es8t35f3gvo51onj3q1omnef00");
    }
    public void loginApplication(String Username, String Password) throws InterruptedException
    {
    driver.findElement(By.name("username")).sendKeys(Username);
    driver.findElement(By.name("password")).sendKeys(Password);
    driver.findElement(By.id("tdb1")).click();
    Thread.sleep(1000);
    }
    public void closeBrowser()
    {
    driver.close();
    }

    public static void main(String[] args) throws InterruptedException 
    {
    Q45519546_find_element obj = new Q45519546_find_element();
    obj.launchApplication();
    obj.loginApplication("admin", "admin@123");
    boolean Aol = driver.findElement(By.xpath("//div[@id='adminAppMenu']//a[contains(.,'Categories/Products')]")).isDisplayed();
    Thread.sleep(1000);
    boolean Bol = driver.findElement(By.xpath("//div[@id='adminAppMenu']//a[contains(.,'Manufacturers')]")).isDisplayed();
    Thread.sleep(1000);
    boolean Col = driver.findElement(By.xpath("//div[@id='adminAppMenu']//a[contains(.,'Reviews')]")).isDisplayed();
    Thread.sleep(1000);
    if (Aol == true && Bol == true && Col == true)
    {
        System.out.println("TestCase 3: + All required links are present");
    }
    obj.closeBrowser();
    }
}

如果这回答你的问题,请告诉我。