phantomJs无法找到vaadin和selenium的dom元素

时间:2016-09-21 07:59:55

标签: java selenium-webdriver phantomjs vaadin

我试图使用幻像js进行vaadin代码的无头测试 通过硒,但我得到例外说“nosuchelementfound”

public class Test extends InitiateTestBench{

TestBenchProperties localProperties = new TestBenchProperties();
static DeviceTypeEnum deviceType = null;
WebDriver classDriver = null;
static List<WebDriver> listOfDrivers = new ArrayList<WebDriver>();



@Test
public void testMapPage_00(@Param(name="some")String some) throws InterruptedException, TestBenchException{

    try {
        localProperties.loadProperties("conf/MapDetail.properties");
        initSetup();
        driver = getDriver();
        this.classDriver = driver;
    driver.get(baseUrl);

    String macid = globalProperties.get("macId"); 
    String username = globalProperties.get("username");
    String password = globalProperties.get("password"); 

    CommonUtills.sleep(5000);
    //**********this is where the error occurs
    driver.findElement(By.id("DC_Login_UserName_Text")).sendKeys(username);

    WebElement passwordTf = driver.findElement(By.id("DC_Login_Password_Text"));        
    passwordTf.clear();
    passwordTf.sendKeys(password);

    driver.findElement(By.id("DC_Login_SignIn")).click();   


    driver.findElement(org.openqa.selenium.By.id("NC_Menu_Content_Search_Mac_Id_TF")).sendKeys(some);
    driver.findElement(By.id("NC_Menu_Content_Search_Button")).click();
    CommonUtills.sleep(3000);
    if(driver.findElement(By.id("DC_Menu_mapdetail_ID")).isDisplayed()){
        driver.findElement(By.id("DC_Menu_mapdetail_ID")).click();

        try {
            Thread.sleep(1000);
            if(driver.findElement(By.id("DC_MapDetails_Location_Tab")).isDisplayed()){
                CommonUtills.sleep(3000);
                driver.findElement(org.openqa.selenium.By.className("v-tabsheet-tabcontainer")).findElement(org.openqa.selenium.By.className("v-tabsheet-tabitem")).click();
                CommonUtills.sleep(3000);
                System.out.println("SYSOUT: Device Console:  Map Detail loaded successfully");
                Assert.assertTrue("Device Console:  Map Detail loaded successfully. ",true);
            }
            else{
                AssertJUnit.fail("Device Console: Map Detail  failed to load.");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } else{
        AssertJUnit.fail("Device Console: Map Detail failed to load."); 
    }
    CommonUtills.sleep(3000);
    listOfDrivers.add(driver);

} catch (Exception e) {
    System.out.println("Property loading is failed.");
    e.printStackTrace();
}
}


@AfterClass
public static void testLogout(){
    for(WebDriver webDriver: listOfDrivers){
        CommonUtills.logoutDeviceConsole(webDriver);
        webDriver.close();
    }
}

public WebDriver getClassDriver() {
    return classDriver;
}

public void setClassDriver(WebDriver classDriver) {
    this.classDriver = classDriver;
}

}

selenium v​​ersion 2.39.0 幻影驱动程序jar版本1.1.0 phantomjs 2.1.1

看到的错误是

[ERROR - 2016-09-21T07:50:11.557Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1474444211547
org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find    element with id 'DC_Login_UserName_Text'","request":{"headers":   {"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"47","Content-Type":"application/json; charset=utf-8","Host":"localhost:44783"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"DC_Login_UserName_Text\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/f0d9c420-7fcf-11e6-aeb2-b7cbd59c9ab0/element"}}


Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=XP, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, driverVersion=1.1.0, locationContextEnabled=false, version=1.9.7, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=false, browserConnectionEnabled=false, webStorageEnabled=false, nativeEvents=true, proxy={proxyType=direct}, applicationCacheEnabled=false, driverName=ghostdriver, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

0 个答案:

没有答案