Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a text box in which when I type one letter say 's' , it displays a list of results ( like google search) .

I am using latest selenium webdriver with java.

I have tried

sendKeys("s"),

JavascriptLibrary jsLib = new JavascriptLibrary();

jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onkeyup");

    jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onblur");

    jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onclick");

    jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onmouseup");


driver.findElement(By.id("assetTitle")).sendKeys(Keys.ENTER);

None of these work even after adding wait after each of the steps.

Any suggestions?

Thanks.

Update :-

WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
    WebElement query = driver.findElement(By.name("q"));
    query.sendKeys("s");
driver.findElement(By.xpath("//table[@class='gssb_m']/tbody/tr/td/div/table/tbody/tr/td/span")).click();
    driver.findElement(By.name("btnG")).click();

Update 2 : -

WebDriver driver = new FirefoxDriver();
    driver.get("http://www.kayak.com/");
    WebElement query = driver.findElement(By.name("destination"));
    query.sendKeys("s");

Update 3 :- I tried with Selenium 1 and the fireevent method works by passing parameter as 'keydown'. This should be a temporary workaround for now.

WebDriver driver = new FirefoxDriver();
    driver.get("http://www.kayak.com/");
    DefaultSelenium sel = new WebDriverBackedSelenium(driver,"http://www.kayak.com/");

    sel.type("//input[@id='destination']", "s");
    sel.fireEvent("//input[@id='destination']", "keydown");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
147 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found a workaround about this. My problem was:

  1. Selenium inputted 'Mandaluyong' to an auto-suggest location field
  2. The auto-suggest field appears together with the matched option
  3. Then selenium left the auto-suggest drop-down open not selecting the matched option.

What I did was:

        driver.findElement(By.name("fromLocation")).sendKeys("Mandaluyong");
        driver.findElement(By.name("fromLocation")).sendKeys(Keys.TAB);

This is because on a manual test, when I try to press TAB key, two things were done by the system:

  1. Picks the matched option from the auto-suggest drop-down
  2. Closes the auto-suggest drop-down

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...