如何通过硒webdriver 识别webelement按钮未定义executeScript方法。在哪里添加这个 driver.executeScript("return $('body /deep/ <#selector>')")
?如何使用硒webdriver识别webelements(按钮,下拉等)
0
A
回答
0
试试下面的代码检索所有下拉值
WebDriverWait wait = new WebDriverWait(d, 10);
WebElement selectMonth = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@title = 'Birthday']")));
selectMonth.click();
List<WebElement> allmonths = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("span#BirthMonth > div.goog-menu.goog-menu-vertical")));
for(WebElement month : allmonths) {
System.out.println(month.getText());
希望这将有助于
0
,我们会得到下面的情形这种类型的异常。
- 如果页面未嵌入
jQuery
。 jQuery
库未成功加载。- 浏览器同步。
首先检查网页被嵌入jQuery
或不通过浏览器控制台下面的命令执行
window.jQuery=='undefine' // Its for checking jQuery is present on page if yes then return true.
和
jQuery.active==0 // Its for checking jquery is activated on page if yes then return true.
然后尝试
String getArgument="0"; // take single element
//String getArgument="";// take list of matched element
((JavascriptExecutor) driver).executeScript("return $(#selector).get(" + getArgument + ");");
0
您可以在下面的代码只需使用标识元素即可getTagName()
如下: -
WebElement element = driver.findElement(By.id("countTd"));
// To verify if element is button
if(element.getTagName().equals("button")) {
element.click();
}
// To verify if element is dropdown
if(element.getTagName().equals("select")) {
// Now pass it to Select class to work
Select selectElement = new Select(element);
// Now you can get all options
List<WebElement> options = selectElement.getOptions();
//Now you can print all options text
for(WebElement option : options) {
System.out.println(option.getText());
}
}
节点: - 有没有必要使用JavascriptExecutor
进行点击,就可以简单地通过调用.click()
方法来执行。
希望它能帮助.. :)
相关问题
- 1. 如何使用Selenium Webdriver识别按钮?
- 2. 硒WebDriver找不到WebElements
- 3. 识别使用硒的网页按钮
- 4. 硒的webdriver无法识别RichFaces的下拉值
- 5. RFT不识别webelements
- 6. 使用classname的硒webdriver下拉选择
- 7. iPhone识别按钮按下
- 8. 如何选择硒下拉值的webdriver如何使用Node.js
- 9. 下拉不硒的webdriver
- 10. 如何检查硒webdriver中的性别选择单选按钮?
- 11. 硒webdriver IE按钮问题
- 12. 如何按使用硒的webdriver
- 13. 如何使用硒webdriver按(ctl + alt + 6)
- 14. 如何使用硒webdriver从下拉框中选择
- 15. 如何选择jQuery无订单下拉列表硒硒webdriver
- 16. 如何识别按钮
- 17. 下拉识别
- 18. 如何使用硒的webdriver
- 19. 如何使用硒的webdriver
- 20. 如何使用硒的webdriver
- 21. 如何使用硒的webdriver
- 22. 在actionscript中识别按钮按下
- 23. VB.NET Inputbox - 如何识别何时按下取消按钮?
- 24. VBScript InputBox - 如何识别何时按下取消按钮?
- 25. IE 11点击一个按钮,并等到超时硒webdriver
- 26. 在引导下拉按钮中无法识别javascript函数
- 27. 如何识别哪个按钮被按下?
- 28. 无法点击硒webdriver中的按钮
- 29. 按钮点击不工作在硒webdriver
- 30. 如何验证在java中使用硒的下拉菜单按钮
尝试this'((JavascriptExecutor)驱动程序).executeScript( “参数[0]。点击();”,元素);'。您必须在自动化代码中相应地更改定位器。 – Harish
你试过这个。它适用于按钮,但下拉如何使用此元素。我想在控制台中打印下拉列表WebElement dropDown = driver.findElement(By.id(“countTd”)); dropDown.click(); driver.findElement(Byxpath(“// td [@ id ='countTd']/span [text()=''']”))。click.getOptions(); –
看到这个http:// stackoverflow.com/questions/6430462/how-to-select-get-drop-down-option-in-selenium-2 – Siva