我正在尝试为输入字段指定邮政编码以获取餐馆位置。我可以指定邮政编码,但无法点击回车键。由于它没有输入按钮,它需要通过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);
}
答案 0 :(得分:0)
WebElement element;
element = driver.findElement("//*[@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);
我检查了它正常工作的代码。