2013-03-17 46 views
1

我正在运行使用硒的webdriver如何点击自动提示输入文本框中的选项? webdriver的

测试硒我有一个问题与输入文本框(“选择来源:名称:”)。 当我在文本框中输入字符串“ABC Premium News(澳大利亚)”时,会显示一个选项。然后我需要点击(或选择)它。我尝试了所有方法w/fireEvent ...没用。

以下是源代码:

driver.get("http://www..."); 
driver.switchTo().frame("mainFrame"); 
WebElement sourceTitle = driver.findElement(By.name("sourceTitle")); 
sourceTitle.sendKeys("ABC Premium News (Australia)"); 
//Now a "combobox-like" option "ABC Premium News (Australia)" shows up...how do I click it? 

// I tried fireEvent...it did not help. The following is one of my trials that does not work: 
DefaultSelenium sel = new WebDriverBackedSelenium(driver,"http://www...."); 
sel.type("//input[@id='destination']", "ABC Premium News (Australia)"); 
sel.fireEvent("//input[@id='destination']", "keydown"); 
// In addition to keydown, I tried: onclick, onfocus, onblur... 
+0

看看这里http://stackoverflow.com/questions/9202061/test-autocomplete-with-selenium-webdriver – 2013-03-17 05:33:44

+0

对不起@Amine Hajyoussef。我再次尝试,似乎这种方法只帮助将值输入到文本文件中,但是,它不会帮助选择“类似组合框”选项。 ANYBODY,请运行上面的代码行或访问网站查看文本框。 – CHEBURASHKA 2013-03-17 06:15:58

+0

你能告诉我们html和截图吗? – 2013-03-18 07:34:45

回答

2

我知道这是不是最好的人能想出但仍可以作为暂时的解决办法。

WebElement sourceTitle = driver.findElement(By.name("sourceTitle")); 

WebElement small = driver.findElement(By.cssSelector("li#nameExampleSection label + small")); 

sourceTitle.sendKeys("ABC Premium News (Australia)"); 

Thread.sleep(5000); 

Actions actions = new Actions(driver); 

actions.click(small).perform(); 
+0

我编辑了答案。它应该工作。核实。 :) – 2013-03-18 18:49:34

+0

谢谢@Code热情! :) – CHEBURASHKA 2013-03-18 18:56:51

相关问题