2016-05-13 85 views
0

我在Windows 8.1中使用Eclipse版本:Luna Release(4.4.0)。我有一个工作正常的硒(V 2.53)代码。当我使用Junit时无法通过ID查找元素

f.get("https://mail.yahoo.com"); 
f.findElement(By.id("login-username")).sendKeys("jj%jo.com"); 

WebElement element = f.findElement(By.id("login-username")); 
String text = element.getAttribute("value"); 
System.out.println(text); 

但是,当我在Project> BuildPath中添加Junit v4.12和TestNG时,代码无法找到该元素。

@Test 
public void testFindUsername(){ 
    f.findElement(By.id("login-username")).click(); 
    f.findElement(By.id("login-username")).sendKeys("[email protected]"); 
} 

Error: Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"login-username"} For documentation on this error, please visit:

http://seleniumhq.org/exceptions/no_such_element.html

如果其他人有这个问题,请让我们知道解决的办法。

谢谢

+0

使一些等待后得到的URL – noor

+0

得到它的工作,谢谢。 –

回答

0
import java.util.Scanner; 

public class CreateGuest { 

    public static void main(String[] args) { 
     String name = getGuestName(); 
     printName(name); 
    } 

    public static String getGuestName() { 
     Scanner in = new Scanner(System.in); 
     System.out.print("Enter name: "); 
     String name = in.next(); 
     in.close(); 
     return name; 
    } 

    public static void printName(String name) { 
     System.out.println("You entered: " + name); 
    } 

} 
相关问题