简体   繁体   English

Selenium Webdriver处理Java脚本文本框

[英]Selenium Webdriver to handle java script text box

I am trying to specify zip code to a input field to fetch the restaurant locations. 我正在尝试在输入字段中指定邮政编码以获取餐厅位置。 I am able to specify the zip code and unable to hit the enter key. 我可以指定邮政编码,但无法按Enter键。 As its doesn't has enter button it needs to be handled via javascript. 由于它没有输入按钮,因此需要通过javascript处理。 Need help in resolving issue: 需要帮助解决问题:

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("//*[@id='location_box']/div[2]/input");
element.sendKeys("84604", Keys.ENTER);

There is an typo error in the above code. 上面的代码中有错字错误。

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

I checked the code it is working fine. 我检查了代码,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM