gpt4 book ai didi

javascript - selenium IDE 试图获得 margin 底值

转载 作者:行者123 更新时间:2023-11-29 15:50:07 25 4
gpt4 key购买 nike

我正在尝试获取页面上某个元素的下边距值。该页面有一个选择框,允许访问者调整元素的底部边距。我想创建一个脚本来更改值,然后检查底部边距是否已更改。我对高度参数做了类似的事情,但有一个特定的断言。如何访问底部边距。

我试过 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 中设置用户扩展文件:

选项 > 选项 >

enter image description here

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>

输出:

  • [信息] 执行:|选择| id=底部边距选择 |标签=10px |
  • [信息] 执行:|storeSelectedLabel | id=底部边距选择 | var_BottomMarginSelect_select_option_selected_text |
  • [信息] 正在执行:|echo | ${var_BottomMarginSelect_select_option_selected_text} | |
  • [信息]回显:10px
  • [信息] 正在执行:|storeStyleAttribute |自定义分区 | |
  • [信息] 正在执行:|echo | ${var_style_attribute_from_custom_command} | |
  • [信息]回显:10px
  • [信息] 正在执行:|assertExpression | ${var_style_attribute_from_custom_command} | ${var_BottomMarginSelect_select_option_selected_text} |
  • [信息] 执行:|storeText |//div[@id='CustomDiv']/@style | var_style_attribute_from_id |
  • [信息] 正在执行:|echo | ${var_style_attribute_from_id} | |
  • [信息] echo: margin-bottom: 10px;
  • [信息] 执行:|storeText |//div[@class='customDiv']/@style | var_style_attribute_from_class |
  • [信息] 正在执行:|echo | ${var_style_attribute_from_class} | |
  • [信息] echo: margin-bottom: 10px;
  • [信息] 正在执行:|storeAttribute | CustomDiv@样式 | var_style_attribute_from_storeAttribute |
  • [信息] 正在执行:|echo | ${var_style_attribute_from_storeAttribute} | |
  • [信息] echo: margin-bottom: 10px;

关于javascript - selenium IDE 试图获得 margin 底值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com