我被困在这上面,希望你能给我指明正确的方向。
我正在使用新的文物监测工具,需要创建一个典型的电子商务用户旅程的监测测试,搜索,选择一个产品,选择一个大小,然后添加到袋。
我得到的问题是,一些产品的尺寸缺货,这打破了我的测试。我有下面的代码,允许我选择特定的产品,但是有人知道如何选择第一个可用的选项吗?
任何帮助都将不胜感激。
谢谢
//Example: Selecting an option and retrieving the selected label/value
var By = $driver.By,
selectbox;
// ----------------------------------------------------------------------------- //
// Helper function that returns the first selected option given a select element
function findSelected(select) {
var d = $driver.promise.defer();
select.findElements(By.tagName('option')).then(function (options) {
options.forEach(function(option) {
option.isSelected().then(function(selected) {
if (selected) {
d.fulfill(option);
}
});
});
});
return d.promise;
}
// ----------------------------------------------------------------------------- //
// Load the page
$browser.get("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_select2").then(function(){
// Focus the iframe
$browser.switchTo().frame("iframeResult");
// Click on select
return $browser.waitForAndFindElement(By.name("cars"), 15000).then(function(elem) {
selectbox = elem;
selectbox.click();
});
}).then(function() {
// Select an option
return selectbox.findElement(By.css("option[value='audi']")).click();
})发布于 2022-07-13 11:02:28
我可以通过使用sendkey向下箭头并进入,如果这对任何人都有帮助的话,就可以绕过这个问题。
https://stackoverflow.com/questions/72910950
复制相似问题