NoSuchElement异常(selenium)

时间:2017-09-27 11:30:47

标签: java selenium

**我使用过POM模型并使用 selenium webdriver Eclipse )来运行我的代码但是我遇到了困难,得到了NoSuchElementException

  

org.openqa.selenium.NoSuchElementException:无法找到element:// input [@id =' email']有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html构建信息:版本:' 3.4.0',修订版:'未知',时间:'未知'系统信息:主机:' ISHWS37',ip:' 10.0.0.60',os.name:' Windows 10',os.arch:' amd64',os.version:' 10.0',java.version:' 1.8.0_111'驾驶员信息:org.openqa.selenium.firefox.FirefoxDriver能力[{转动=假,raisesAccessibilityExceptions =假,appBuildId = 20160421124000,版本= 46.0,平台= XP,代理=代理(),specificationLevel = 1,acceptSslCerts =假,browserVersion = 46.0,platformVersion = 10.0,XULappId = {ec8030f7-C20A-464f-9b0e-13a3a9e97384},browserName =火狐,takesScreenshot =真,takesElementScreenshot =真,javascriptEnabled =真,platformName = Windows_NT,设备=桌面}]会话ID:02585599 -6b3e-4c03-9b2b-04291afa2052 ***元素信息:{using = xpath,value = // input [@id =' email']} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)在sun.reflect.NativeConstructorAccessorImpl.newInstance(未知来源)在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知来源)在java.lang.reflect.Constructor.newInstance(未知来源)在org.openqa.selenium.remote.http.W3CHttpResponseCodec org.openqa.selenium中的.createException(W3CHttpResponseCodec.java:150)。 remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor。的java:164)在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)在org.openqa.selenium .remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410)org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:509)org.openqa.selenium.By $ ByXPath.findElement(By.java:361) )在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402)在com.babysden.pages.Loginpage.type_username(Loginpage.java:28)在com.babysden.testcases.Verify_login.verifylogin(Verify_login。 java:37)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeM ethodAccessorImpl.invoke(未知来源)在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)在java.lang.reflect.Method.invoke(未知来源)在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)在org.testng.internal.Invoker.invokeMethod(Invoker.java:645)在org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)在org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177 )在org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)在org.testng.TestRunner.privateRun(TestRunner.java:756)在org.testng.TestRunner.run(TestRunner.java:610)在org.testng.SuiteRunner.runTest(SuiteRunner.java:387)在org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)在org.testng。 SuiteRunner.privateRun(SuiteRunner.java:340)org.testng.SuiteRunner.run(SuiteRunner.java:289)at org.testng.SuiteRunnerWorker.run套房(SuiteRunnerWorker.java:52)在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)在org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)在org.testng.TestNG.runSuitesLocally(TestNG.java :1218)在org.testng.TestNG.runSuites(TestNG.java:1133)在org.testng.TestNG.run(TestNG.java:1104)在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)在Org.testng.remote.remitAndRun(RemoteTestNG.java:236)org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)上的org.testng.remote.RemoteTestNG.initAndRun。   当我执行代码之前没有抛出这样的元素也是我输入的XPath是正确的,我已经验证了它。       公共类登录页面       {           WebDriver驱动程序;           通过Click_loginbtn = By.className(" login-text");           用户名= By.xpath(" //输入[@id ='电子邮件']"); //无法找到           通过pwd = By.className(" input-text required-entry validate-password form-control"); //无法找到           通过login_btn = By.name(" send");           通过homepage = By.className(" lazy img-responsive");           公共登录页面(WebDriver驱动程序)           {               this.driver =驱动器;           }           public void Click_loginbtn()           {               driver.findElement(Click_loginbtn)。单击();           }           public void type_username()           {               driver.findElement(用户名).sendKeys(" xyz.com&#34);           }           public void type_pwd()           {               driver.findElement(PWD).sendKeys(" vkt123456&#34);           }           public void type_login_btn()           {               driver.findElement(login_btn)。单击();           }}               和          公共类Verify_login          {           WebDriver驱动程序;           @BeforeMethod           public void OpenBrowser()抛出InterruptedException {           driver = new FirefoxDriver(); //启动浏览器           。driver.manage()窗口()最大化(); //最大化窗口           driver.manage()。timeouts()。implicitlyWait(60,TimeUnit.SECONDS);           driver.get(" http://babysden.demo2clients.com/&#34); //导航到Url           System.out.println(" Url正在出现");           了Thread.sleep(2000);           }           @测试           public void verifylogin()throws InterruptedException {           登录页面lp =新登录页面(驱动程序); //做了一个登录对象

    lp.Click_loginbtn(); //calling loginbtn from LoginpAGE Class
    Thread.sleep(1000);
    System.out.println("Clicking on login btn");

    lp.type_username(); //calling type_username from Loginpage Class
    Thread.sleep(1000);
    System.out.println("Enter username");

    lp.type_pwd(); //calling type_pwd from Loginpage Class
    Thread.sleep(1000);
    System.out.println("Enter Password");

    lp.type_login_btn(); //calling type_login_btn from Loginpage Class
    Thread.sleep(1000);
    System.out.println("Click on login");
    }

1 个答案:

答案 0 :(得分:-1)

尝试此代码它正在运行:

package main

import (
    "fmt"
    "go/ast"
    "go/parser"
    "go/token"
)

func main() {
    src := `package test

    // Hello
    type A struct {
        // Where
        B int // Are you
    }
    `

    fset := token.NewFileSet()
    f, err := parser.ParseFile(fset, "", src, 0)
    if err != nil {
        panic(err)
    }

    ast.Inspect(f, func(n ast.Node) bool {
        switch t := n.(type) {
        case *ast.TypeSpec:
            fmt.Println(t.Doc.Text())
        case *ast.StructType:
            for _, field := range t.Fields.List {
                fmt.Println(field.Doc.Text())
                fmt.Println(field.Comment.Text())
            }
        }
        return true
    })
}