- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试获取页面上某个元素的下边距值。该页面有一个选择框,允许访问者调整元素的底部边距。我想创建一个脚本来更改值,然后检查底部边距是否已更改。我对高度参数做了类似的事情,但有一个特定的断言。如何访问底部边距。
我试过 assertAtribute elementid@style
但这只是给出了包含其他值的整个STLye。
我在下面包含了我的高度脚本,尽管它对我帮助不大
<tr>
<td>select</td>
<td>headerHeightSet</td>
<td>label=100</td>
</tr>
<tr>
<td>storeSelectedValue</td>
<td>headerHeightSet</td>
<td>topMarginValue</td>
</tr>
<tr>
<td>assertElementHeight</td>
<td>wemakeSheetHeaderJpg</td>
<td>${topMarginValue}</td>
</tr>
最佳答案
是的,根据我的发现,“storeAttribute”命令效果不佳。我找到了几种不同的方法来做到这一点,但我认为使用用户扩展是最好的方法。
HTML:
<html>
<head>
<script src="jquery-1.6.2.js"></script>
<style type="text/css">
body
{
margin:0px 0px 0px 0px;
}
.customDiv
{
border-style:solid;
border-color: green;
margin: 5px 50px 10px 0px; /* top bottom right left */
margin-color: black;
background-color: red;
padding: 50px 50px 50px 50px;
}
</style>
<script>
$(document).ready(function() {
jQuery("#BottomMarginSelect").change(function() {
jQuery("#CustomDiv").css("margin-bottom",jQuery("#BottomMarginSelect").val());
//alert(jQuery("#CustomDiv").css("margin-bottom"));
});
});
</script>
</head>
<body>
<div id="CustomDiv" class="customDiv">
text in div
</div>--- bottom margin of div ends here (100px below green div border); margin is always transparent ----
<br />
<br />
<b>Select the bottom margin of the div:<b><br />
<select id="BottomMarginSelect">
<option value="10px">10px</option>
<option value="20px">20px</option>
<option value="30px">30px</option>
</select>
</body>
</html>
创建一个名为“user-extensions.js”的文件并将此代码放入其中:
Selenium.prototype.doStoreStyleAttribute = function(locator) {
var val = selenium.browserbot.getCurrentWindow().document.getElementById(locator).style.marginBottom;
this.doStore(val,"var_style_attribute_from_custom_command");
};
在 Selenium-IDE 中设置用户扩展文件:
选项 > 选项 >
Selenium 命令:
<tr>
<td>select</td>
<td>id=BottomMarginSelect</td>
<td>label=10px</td>
</tr>
<tr>
<td>storeSelectedLabel</td>
<td>id=BottomMarginSelect</td>
<td>var_BottomMarginSelect_select_option_selected_text</td>
</tr>
<tr>
<td>echo</td>
<td>${var_BottomMarginSelect_select_option_selected_text}</td>
<td></td>
</tr>
<tr>
<td>storeStyleAttribute</td>
<td>CustomDiv</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${var_style_attribute_from_custom_command}</td>
<td></td>
</tr>
<tr>
<td>assertExpression</td>
<td>${var_style_attribute_from_custom_command}</td>
<td>${var_BottomMarginSelect_select_option_selected_text}</td>
</tr>
<tr>
<td>storeText</td>
<td>//div[@id='CustomDiv']/@style</td>
<td>var_style_attribute_from_id</td>
</tr>
<tr>
<td>echo</td>
<td>${var_style_attribute_from_id}</td>
<td></td>
</tr>
<tr>
<td>storeText</td>
<td>//div[@class='customDiv']/@style</td>
<td>var_style_attribute_from_class</td>
</tr>
<tr>
<td>echo</td>
<td>${var_style_attribute_from_class}</td>
<td></td>
</tr>
<tr>
<td>storeAttribute</td>
<td>CustomDiv@style</td>
<td>var_style_attribute_from_storeAttribute</td>
</tr>
<tr>
<td>echo</td>
<td>${var_style_attribute_from_storeAttribute}</td>
<td></td>
</tr>
输出:
关于javascript - selenium IDE 试图获得 margin 底值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558756/
当我设置 margin-right: 50px;我没有看到任何效果,但是当我替换 margin-right: 50px; 时左边距:50px;或 margin-top: 50px;我确实看到了效果。这
CSS .title{ margin-top: 200px; // does not work! margin-left: 20px; font-weight: bold;
我不知道,但是 li 元素的 margin-top 只有在它大于 h2 元素的 margin-bottom 时才会起作用,我想知道为什么? Test1 Test2 谢谢。 最佳答案 您所描述的听起
我有 2 个 div 的问题 - 两个呈现为 block 的边距均为 15px(顶部 div 有底部边距,底部有顶部),因此我预计两者之间的差距是 30px 而不是 15px,这是正确的假设还是我要疯
我一直以为我了解利润率和负利润率,但显然我不了解!我刚刚开始一个新的设计并且已经遇到了问题。 我有一个 div (hill3Cont) 和另一个嵌套在里面的 div (hill3Hill),这是它们的
我有一系列这样的元素: ... ....... ... ....... h1 上边距为 5px,p 上边距为 10px。但是产生的边距只有 10px。如果我将底部边距增加到 50px,将顶部边距增加
由于 margin-right: auto 和 margin-left: auto 水平居中元素,我希望它们的垂直对应物以相同的方式运行。 但我知道这不会发生,根据 CSS 规范: 10.6.2 In
我在让我的 div 将我的页面向下移动 30 像素/在我的 div 顶部添加边距 30 像素时遇到问题。我的 div 使用 margin auto 在页面中心对齐。 然而,当我尝试添加这行代码时:边距
这个问题在这里已经有了答案: CSS margin terror; Margin adds space outside parent element [duplicate] (7 个答案) 关闭
我有一个 div 在另一个之上。顶部的 div 有 margin-bottom: 10px,底部的 div 有 margin-top: 10px,但两个 div 之间只有 10px 的空间。 实例:h
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 2 年前。 我的 CSS 边距没有按照我想要或期望的方
在此website我正在尝试减少横幅和文本之间ON MOBILE 底部和顶部的边距。 如果您在智能手机和平板电脑上查看,横幅的顶部和底部似乎有一些边距。 这是我的 CSS: .page-id-996
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
我是一名优秀的程序员,十分优秀!