如何通过硒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. 无法识别使用硒的naukri.com应用程序的登录按钮Webdriver
- 6. RFT不识别webelements
- 7. 使用classname的硒webdriver下拉选择
- 8. 如何退出硒webdriver下拉菜单
- 9. 我们如何识别硒webdriver中的开关按钮的状态
- 10. iPhone识别按钮按下
- 11. 如何选择硒下拉值的webdriver如何使用Node.js
- 12. 使用硒webdriver切换按钮单击
- 13. 使用硒webdriver选择日历按钮
- 14. 下拉不硒的webdriver
- 15. 如何等待一个按钮被点击在硒webdriver c#中?
- 16. 使用硒webdriver代码点击下拉按钮时面临的问题
- 17. 如何检查硒webdriver中的性别选择单选按钮?
- 18. 硒webdriver IE按钮问题
- 19. 硒的webdriver按钮定位
- 20. 如何按使用硒的webdriver
- 21. 如何使用硒webdriver按(ctl + alt + 6)
- 22. 如何使用硒webdriver从下拉框中选择
- 23. 如何选择使用硒webdriver多个下拉
- 24. 如何在硒webdriver中使用下拉选项获取下拉选项值
- 25. c#如何使用硒webdriver点击按钮?
- 26. 硒的webdriver不能识别网页上
- 27. 如何选择jQuery无订单下拉列表硒硒webdriver
- 28. Selenium webdriver识别按钮并点击它使用Java
- 29. 如何识别按钮
- 30. 下拉识别
尝试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