java 如何使用硒类型的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13897076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use a selenium type method?
提问by zfranciscus
I have a JSP page with a input text field.
我有一个带有输入文本字段的 JSP 页面。
<table>
<tr>
<td><input type="text" id="searchText" name="searchInput"/></td>
</tr>
</table>
I wrote a selenium test case that verifies that the search input text is present.
我编写了一个 selenium 测试用例来验证搜索输入文本是否存在。
public class UIRecipeListTest extends SeleneseTestBase {
@Before
public void setup() {
WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File(
"C:\Program Files (x86)\Mozilla Firefox 3.6\firefox.exe")), new FirefoxProfile());
String baseUrl = "http://localhost:8080/RecipeProject/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}
@Test
public void testShowRecipes() {
verifyTrue(selenium.isElementPresent("searchText"));
selenium.type("searchText", "salt");
}
}
The verifyTrue
test returns true
. However, selenium.type
test failed with this error:
该verifyTrue
试验的回报true
。但是,selenium.type
测试失败并出现此错误:
com.thoughtworks.selenium.SeleniumException: Element searchText not found
com.thoughtworks.selenium.SeleniumException: Element searchText not found
What should I do to make the test work?
我应该怎么做才能使测试工作?
回答by ddavison
The first parameter needs to be a selector. searchText
isn't a valid CSS or xpath selector.
第一个参数需要是一个选择器。 searchText
不是有效的 CSS 或 xpath 选择器。
you would use something like selenium.type("css=input#searchText", "salt");
你会使用类似的东西 selenium.type("css=input#searchText", "salt");
Also wanted to point out that you seem to be going between the 2 version of Selenium.
还想指出您似乎在 Selenium 的 2 版本之间。
selenium.type(String,String)
is from the Selenium 1 API. You should keep to 1 version, and if it's going to be Selenium 2, you need to do something like,
selenium.type(String,String)
来自 Selenium 1 API。你应该保持 1 个版本,如果它是 Selenium 2,你需要做一些类似的事情,
WebElement element = driver.findElement(By.id("searchText"))
and use
element.sendKeys("salt");
WebElement element = driver.findElement(By.id("searchText"))
并使用
element.sendKeys("salt");
Source: Selenium API type(String,String)