我该如何解决这个问题?
public class myClass {
WebDriver driver;
@Test
public void myTest() {
oasEnterValue("//input[@name='user']", "user1");
oasEnterValue("//input[@name='password']", "pwd1");
}
public void oasEnterValue(String fXPath, String fText) {
driver.findElement(By.xpath(fXPath)).sendKeys(fText);
}
}
我在NullpointerException
driver.findElement(By.xpath(fXPath)).sendKeys(fText);
以下是我的完整代码:
public class myClass {
WebDriver driver;
@Test
public void myTest() {
browserGo("linkedin.com/");
oasEnterValue("//input[@name='user']", "user1");
oasEnterValue("//input[@name='password']", "pwd1");
}
public void oasEnterValue(String fXPath, String fText) {
driver.findElement(By.xpath(fXPath)).sendKeys(fText);
}
public void browserGo(String fURL) {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(fURL);
}
答案 0 :(得分:0)
据我所知,那些XPath不存在。我想你想要:
oasEnterValue("//*[@id='login-email']", "user1");
oasEnterValue("//*[@id='login-password']", "pwd1");