Click()或Submit()不适用于Selenium java代码
Click() or Submit() is not working for Selenium java code
我正在尝试在搜索框中输入文本,点击文本应该会打开它下面的链接。到目前为止,我可以在搜索框中输入文本,但输入、单击或提交都无法识别。理想情况下,如果我们输入文本并单击enter,它应该显示搜索文本中的元素。
Web驱动程序代码:
WebDriverWait wait = new WebDriverWait(wd, 100);
wait.until(ExpectedConditions.presenceOfElementLocated(By.className("span16")));
WebElement signupForm = wd.findElement(By.className("span16"));
signupForm.sendKeys("MTestin");
WebDriverWait wait1 = new WebDriverWait(wd, 100);
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("omedia-search"))).click();
页面HTML:
<div class="row-fluid sort-text">
<input id="searchbox" class="span16" type="text" placeholder="showing all result" data-provide="typeahead" name="input" />
<i class="omedia-search"></i>
</div>
您在wait.until...
上执行click
,而不是在元素本身上。
你也需要为按钮做一个wd.findElement
,就像你为搜索框做的一样。
此外,我认为在第一次wait
调用完成后,可以安全地假设页面已完全加载,因此也无需等待找到按钮。
以下是我的做法:
WebDriverWait wait = new WebDriverWait(wd, 100);
wait.until(ExpectedConditions.presenceOfElementLocated(By.className("span16")));
WebElement signupForm = wd.findElement(By.className("span16"));
signupForm.sendKeys("MTestin");
WebElement submitButton = wd.findElement(By.className("omedia-search"));
submitButton.click();
顺便说一句,你的搜索条件不是很好——类span16
是结构化的,所以如果页面设计发生变化,它可能会出现在其他地方。相反,搜索字段的id
,因为它在正确构建的页面上是唯一的。
相关文章:
- WebDriverException:tinyMCE未在selenium Web driver java中定义
- 等待,直到使用Java在selenium网络驱动程序中手动单击登录按钮
- Java Selenium 2.0-在WebElement.click()之前使用内置滚动时处理z索引(navi)
- 使用 Selenium 和 java 测试 React JS 下拉列表
- 如何使用Java在Selenium WebDriver的隐藏字段中键入一些文本
- 使用Java脚本跟踪网页中是否有Ajax请求,或者通过Selenium Web驱动程序拦截XMLHttpRequest
- Selenium-webdriver (Java Script) 等待元素消失
- 当尝试登录instagram时,带有Selenium的Phantomjs不处理iframe Java脚本
- Java Selenium-JavaScriptExecutor-Argument的类型非法:driverFactory
- 如何将JavaScript与Selenium WebDriver Java结合使用
- Selenium Web驱动程序使用Java查找Element
- Selenium Java-通过JavascriptExecutor获取页面源代码
- Javascript 在 Java Selenium Webdriver 中的使用
- JavascriptExecutor(用于Selenium - Java)无法按FF 24.0的预期工作
- 如何使用Selenium Webdriver和Java从href html标签中选择“Page=?” valuse
- Selenium Java CSS Selector bug?
- 为什么我必须添加+ I +到第二个WebElement在Selenium Java循环
- Click()或Submit()不适用于Selenium java代码
- 如何知道javascript代码是否已经在Selenium Java中执行
- 第节中的Selenium Java滚动条