我想要一个使用selenium web驱动程序库为C#自动化编写脚本的解决方案,我必须存储所有禁用的值,然后单击它们。实际上,验证就像我不应该能够点击下拉列表中的禁用值。所以我需要两件事的帮助:
代码如下:
<select name="ctl00" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$\',\'\')', 0)" id="ctl00_ctl00_" style="width:200px;">
<option value="1" disabled="disabled">A</option>
<option selected="selected" value="2" enabled="enabled">B</option>
<option value="3" disabled="disabled">C</option>
<option value="4" disabled="disabled">D</option>
</select>
因此,A、C和D是我想要验证的选项。需要帮助:)提前谢谢
发布于 2018-06-26 06:05:12
我使用类似这样的东西在我的页面中搜索“正在加载”的类,以检查正在加载的元素。我重新定义了检查“禁用”类的方法,将它们传递到一个数组中,然后单击。没有经过测试,但希望能将您引向正确的方向。
new WebDriverWait(driver, MyDefaultTimeout)
.Until(e => ((IJavaScriptExecutor)e)
.ExecuteScript(""+
"do {"+
// Find loading element(s)
"var element = document.getElementsByClassName('disabled');"+
// Create array of elements
"var elementList = Array.prototype.slice.call(element);"+
"if(!elementList === undefined && !elementList == 0) {"+
// Map Id and Attribute
"var array = elementList.map(function(v){ return {'ID': v.id} });"+ //"'Attr': v.getAttribute('data-custAtt')"+
// Output array of disabled objects
"console.log(array);"+
// Check to see if array is empty
"if (!array === undefined && !array.length == 0) {"+
// Click disabled element
"var i;"+
"for (i=0;i<array.length;i++){"+
"var disabledElement = array[i];"+
"disabledElement.click();}";"+
"}"+
"else"+ // Array is empty, exit the loop
"{"+
"done = true;"+
"}"+
"}"+
"else"+
"{"+
// We may not have an array of elements
// So if we only have 1
"if(!element === undefined) {"+
// Click disabled element
"element.click();"+
"}"+
"else"+
"{"+
"done = true;"+
"}"+
"}"+
"}"+
"while(done = 'false');")
.Equals("complete"));
https://stackoverflow.com/questions/51018152
复制相似问题