Selenium Webdriver处理java脚本文本框

Selenium Webdriver处理java脚本文本框,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在尝试为输入字段指定邮政编码以获取餐厅位置。我可以指定邮政编码,但无法按enter键。因为它没有回车按钮,所以需要通过javascript处理。需要帮助解决问题: public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); String baseURL = "http://www.thecheese

我正在尝试为输入字段指定邮政编码以获取餐厅位置。我可以指定邮政编码,但无法按enter键。因为它没有回车按钮,所以需要通过javascript处理。需要帮助解决问题:

public static void main(String[] args) {
    // TODO Auto-generated method stub
    WebDriver driver = new FirefoxDriver();
    String baseURL = "http://www.thecheesecakefactory.com/";
    driver.get(baseURL);
    // Go to Menu
    driver.findElement(By.xpath("//*[@id='topNav']/li[1]/a")).click();
    // Click on Pizza
    driver.findElement(By.xpath("//*[@id='firstScroller']/li[7]/a")).click();
    // Select Hawallian Pizza
    driver.findElement(By.xpath("//*[@id='secondScroller']/li[6]/a")).click();
    //String pageTitle = "Hawaiian Pizza";
    String aTitle = driver.getTitle();
    if (aTitle.equalsIgnoreCase("Hawaiian Pizza")){
        System.out.println("Yes its Hawaiian Pizza");
        System.out.println(driver.getTitle());
    }
    //Click to order and get locations
    driver.findElement(By.xpath("//*[@id='receiptMenu']/div[1]/div[3]/div/a/b")).click();
    WebElement element;
    element = driver.findElement(By.xpath("//*[@id='location_box']/div[2]/input"));
    element.sendKeys("84604", Keys.ENTER);
}
上面的代码中有一个打字错误

WebElement element;
element = driver.findElement(By.xpath("//*[@id='location_box']/div[2]/input"));
element.sendKeys("84604", Keys.ENTER);

我检查了代码,它工作正常。

您刚才给出的内容毫无意义。您必须解释您面临的问题是什么。出于好奇,为什么要使用xpath查找所有内容?如果您首先尽可能地使用id和class等属性,您的测试代码将更加清晰。感谢您指出,尽管上面的代码发生了更改,但它仍然不起作用。在输入框中输入了指定的邮政编码,但Keys.ENTER无效。嗯,它对我不起作用:(当我手动按ENTER键时,将显示结果。是否有我出错的线索?我不知道发生了什么错误。请尝试使用class或class。
WebElement element;
element = driver.findElement(By.xpath("//*[@id='location_box']/div[2]/input"));
element.sendKeys("84604", Keys.ENTER);