1

我正在使用 Selenium WebDriver 运行测试

我对输入文本字段("Select Source: By Name:")有疑问。当我在文本字段中输入字符串“ABC 高级新闻(澳大利亚)”时,会显示一个选项。然后我需要单击(或选择)它。我尝试了所有带有 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...
4

1 回答 1

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();
于 2013-03-18T17:34:44.190 回答