如何调用一个方法,其中两个参数为xPath,另一个为sendkey值?

时间:2015-08-19 10:57:29

标签: java xpath selenium-webdriver webdriver

我该如何解决这个问题?

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);
}

1 个答案:

答案 0 :(得分:0)

据我所知,那些XPath不存在。我想你想要:

oasEnterValue("//*[@id='login-email']", "user1");
oasEnterValue("//*[@id='login-password']", "pwd1");