- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有 md-sidenav 的网页,我正在尝试使用 selenium 进行测试。我在页面上所做的一切都有效,除非我尝试单击 md-sidenav 中的元素。当使用 driver.findElement(By.name("elementName") 或通过 id 访问 md-sidenav 内的 web 元素时,我看到该元素不为空。此外,当访问 an 时,我可以访问它的所有子 -元素。但是当我尝试单击它们时,它给了我一个 ElementNotVisibleException:无法单击元素
这是 HTML:
<body ng-controller='MyController as my' ng-cloak>
<section layout="row" column>
<md-sidenav id="sideNavRight" class="md-sidenav-right" md-component-id="right" ng-init="my.selectTab(1)">
<div ng-controller="MyController" ng-show="my.isSelected(1)">
<md-toolbar class="md-theme-light">
<h1 class="md-toolbar-tools">Some Form</small>
<md-button id="navClose" ng-click="close()" class="closeIcon" aria-label="Close">
<md-icon md-svg-icon="assets/img/ic_close_white_24px.svg"></md-icon><sr-only>Close</sr-only>
</md-button></h1>
</md-toolbar>
<md-content>
<div layout="column" index="0">
<h3>Some Information</h3> <br />
<form name="myForm">
<div layout="row" layout-align="start" flex="100">
<md-input-container flex="">
<label>Category:</label>
<md-select name="category" required="" ng-model="menu.category" >
<md-option class="choices" value="cat1">Category1</md-option>
<md-option value="cat2">Category2</md-option>
<md-option value="cat3">Category3</md-option>
</md-select>
<div class="errors" ng-messages="myForm.category.$error">
<div ng-message="required">Required</div>
</div>
</md-input-container>
</div>
<div layout="row" class="pull-right">
<md-button class="btn" ng-click="clearValue()">Clear</md-button>
<md-button class="btn" ng-click="menu.updateCart();menu.selectTab(2);">Next</md-button>
</div>
</form>
</div>
</md-content>
</div>
</md-sidenav>
</section>
....
rest of the page
....
</body>
这是 Selenium 代码:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class EcsTest {
static WebDriver driver;
static Wait<WebDriver> wait;
static String prevText = "";
static String currText = "";
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","C:\\Dvp\\Irs\\EcsTest\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
wait = new WebDriverWait(driver, 30);
driver.get("http://localhost:8080/ecs/index.html");
try {
driver.findElement(By.id("element1")).click();
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver webDriver) {
currText = webDriver.findElement(By.id("field1")).getText();
return !prevText.equals(currText);
}
});
prevText = currText;
driver.findElement(By.id("element2")).click();
//driver.findElement(By.name("dispositionSelect")).sendKeys("Add to Scheme");
Select selectElement = new Select(driver.findElement(By.name("selectElement1")));
disposition.selectByVisibleText("Some form");
WebElement sideNav = driver.findElement(By.id("sideNavRight"));
WebElement closeBtn = sideNav.findElement(By.id("navClose"));
/*
This prints out:
sideNav is not null!, closeBtn is not null!, not displayed!, enabled!
*/
System.out.println(
"sideNav is " + ((sideNav == null) ? "null!" : "not null!") +
", closeBtn is " + ((closeBtn == null) ? "null!" : "not null!") +
", " + ((closeBtn.isDisplayed()) ? "displayed!" : "not displayed!") +
", " + ((closeBtn.isEnabled()) ? "enabled!" : "not enabled!"));
WebElement select = sideNav.findElement(By.name("category"));
List<WebElement> options = select.findElements(By.tagName("md-option"));
/*
This prints out:
select: category, visible: false
*/
System.out.println(
"select: " + select.getAttribute("name") + ", visible: " + select.isDisplayed());
/*
This crashes:
ElementNotVisibleException: Cannot click on element
Without this click, I can see the options fine but the option click crashes
*/
select.click();
for(WebElement option : options) {
System.out.println("option: " + option.getAttribute("value"));
if(option.getAttribute("value").equals(optionName)) {
option.click();
System.out.println("option: " + option.getAttribute("value") + " clicked!");
break;
}
}
} catch (Exception exp) {
exp.printStackTrace();
}
finally {
driver.close();
}
}
}
任何帮助将不胜感激!
最佳答案
尝试添加一些等待所述元素可见:
WebDriverWait wait = new WebDriverWait (driver,20);
wait.until(ExpectedConditions.visibilityOf(select));
select.click();
如果您仍然无法单击该元素,请尝试使用以下答案之一中提到的 Actions 类
。
关于java - Selenium 如何在 md-sidenav 中单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43795477/
我想在 md-toolbar 中使用 mf-tabs,我使用 Sithdown 在 https://github.com/angular/material/issues/1076 中提供的解决方案 它
我是新手,我设法用服务提供的数据实现了我的 md-table。现在我正在尝试实现过滤器、排序和分页功能,但我认为我做错了什么。 这是我的组件: import { Component, OnInit,
我必须打开一个 md-dialog,其中包含一个带有两个选项卡的 md-tab-group。 md-dialog 可以从两个按钮打开,这两个按钮应该打开相应的选项卡。打开 md-dialog 的模板:
我正在尝试做这样的事情: {{item}}
我正在尝试使用 md-datepicker 遍历一个月的时间间隔,因此我创建了这个 codepen 示例以便更好地演示: http://codepen.io/anon/pen/ygBGOg 当单击“P
这是关于 Codepen 的例子. 我正在设置 md-row-height="30px" 然后计算 md-rowspan 使其等于元素数 + 1。(头部加一) {{ t
当我频繁切换 md-tabs 时,Md-tabs 切换正确但多个 md-tab-item 元素同时具有“md-active”类,所以我看不到选项卡的内容是事件的,因为它与其右侧选项卡的内容重叠。 据我
我想将操作放在同一数据行上,我有两个操作,为此我使用按钮和图标作为下面的代码。 {{item.codigo}} {{it
在我的对象列表中,我可以激活/非事件对象。因此,一个图标执行事件操作,另一个图标执行非事件操作,并且两者都在同一个 md-list 中。 This is what i'm tring to do 代码
如前所述 Angular-Material md-autocomplete's documentation : The md-autocomplete uses the the md-virtual-
我也在使用 Angular 1 和 Angular Material 。我想在 ng-repeat 中使用 md-subheader 和多个 md-virtual-repeat-container。您
我正在使用 Angular Material 。 当我创建自己的指令并将其添加到 md-tab-label 时,例如 Label 然后自定义指令也应用于一些“md-dummy-tab”。 但是
我在我的项目中使用 Angular Material 有一段时间了。在使用 md-select 时,我遇到了一个问题,即出现重复的 md-option 值错误。 我知道 md-options 采用唯一
我正在根据单选按钮选择设置自动完成验证 md-require-match = true/false。 默认验证是 md-require-match = true 这样用户应该从自动完成列表中选择一个项
这个问题在这里已经有了答案: Changing capitalization of filenames in Git (11 个答案) 关闭 3 年前。 我使用“readme.md”创建了我的存储库
Github有办法吗?在例如 README.md 中包含 md 文件? # Headline Text [include](File:load_another_md_file_here.md) 它不应
我正在使用 AngularJs 开发这个动态过滤系统,并试图找出如何将 color 和 size 选项转换为在两个下拉列表中(每个类别一个)。 我尝试了以下代码,该代码成功添加了下拉列表以及选择框中的
var app = angular.module('tabsDemo', ['ngMaterial']); app.controller('TabsController',tabsController
在 md-tab 指令内嵌套 md-select 和搜索输入时遇到问题。 有两个问题: 选择框展开后,必须向上滚动才能查看搜索输入 搜索输入实际上不接受任何文本 我做了一个codepen为了更好地说明
我正在尝试处理这个片段,其中自动完成功能嵌入在芯片中。但从自动完成中选择的项目不会转换为筹码。 自动完成的数据采用以下方式:{name:"John Doe", id:"1"} 哪里错了,请指教。 问候
我是一名优秀的程序员,十分优秀!