繁体   English   中英

硒中没有此类元素异常

[英]No Such Element Exception in Selenium

我们已经使用普通的HTMLCSS开发了整个应用程序。 普通记录,并使用Selenium IDE戏是工作完全 正常 ,但是当我们使用 的webdriver编写一个脚本这是引发错误的“NoSuchElementException异常 ”。

package test;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class olp {

    WebDriver driver = null;

    @Before
    public void setUp() throws Exception {
        driver = new InternetExplorerDriver();
        driver.get("http://10.67.89.15/olp/index.html");
    }

    @After
    public void tearDown() throws Exception {

    }

    @Test
    public void test() throws Exception {
        driver.findElement(By.linkText("Sign In")).click();
        driver.findElement(By.xpath("//*[@id='uname']")).sendKeys("user_sam");
        driver.findElement(By.xpath("//*[@id='pas']")).sendKeys("special26");
        driver.findElement(By.xpath("//*[@id='loginb']")).click();      
    }

}

这是我编写的代码。

<div class="form-group">
  <label for="uname">User Name:</label>
  <input type="text" class="form-control" id="uname" name="name" placeholder="Enter User Name" value="">
    <div id="uerror" class="error"></div>
</div>
<div class="form-group">
  <label for="pas">Password:</label>
  <input type="password" class="form-control" name="password" id="pas" placeholder="Enter password" value="">
  <div id="perror" class="error"></div>
</div>
<button type="button" class="btn btn-primary center-block" id="loginb" >SIGN IN</button>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM