我想检查我的复选框是否未选中,唯一更改的参数是aria-label。
是否可以在Sélenium上使用javascript检查该参数?
<svg class="1-MuiSvgIcon-root-778 1-makeStyles-root-875" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="img" aria-label="CheckBoxOutlineBlankIcon"><path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"></path></svg>提前谢谢。
发布于 2022-08-11 15:52:43
aria- dom元素属性只是另一个getAttribute,因为它存在于dom中,所以您可以通过getAttribute获得它。
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var driverPath = require('chromedriver').path;
var By = webdriver.By;
var Key = webdriver.Key;
var until = webdriver.until;
async function start() {
var service = new chrome.ServiceBuilder(driverPath).build();
chrome.setDefaultService(service);
var driver = await new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
await driver.get('http://localhost:9000');
const svgElements = await driver.findElements(By.className("1-MuiSvgIcon-root-778 1-makeStyles-root-875"));
var firstSvg = await svgElements[0];
console.log(firstSvg);
console.log("aria-label value = "+await firstSvg.getAttribute('aria-hidden'))
await driver.quit();
}
start();结果:

发布于 2022-08-11 21:59:36
若要验证是否选中/未选中复选框,可以提取aria-label属性值以进一步探测,如下所示:
发布于 2022-08-12 06:35:43
谢谢大家
感谢你的帮助,我终于找到了我的咏叹调参数。由于等待和console.log对我不起作用(无效),我修改了一点,现在它工作了!
在这里,我所做的:
var test = driver.findElement(By.xpath("//*[name()='svg' and contains(@class, '1-MuiSvgIcon-root-778 1-makeStyles-root-875')]")).getAttribute("aria-label");
System.out.println(test);结果=> CheckBoxOutlineBlankIcon
再次感谢!
https://stackoverflow.com/questions/73323239
复制相似问题