作为我测试的一部分,系统应该查明用于打开网站的设备是移动设备还是普通桌面。找出类名是否包含某些文本
我不断收到错误:
从萤火"InvalidSelectorError: Unable to locate an element with the xpath expression //*[contains(@class, is-mobile..."
物业:
<body class="login-page is-desktop">
我的测试:
public class isMobile {
public static boolean isMobile = false;
public static boolean checkIfMobile(WebDriver driver) throws Exception {
List<WebElement> list = driver.findElements(By
.xpath("//body[contains(@class, 'is-mobile'"));
if (list == null) {
return false;
} else {
return true;
}
}
}
有人可以告诉我正确的XPath应该如何?
或者,首先获取body元素(使用任何你想要的方法 - 例如'// body'),然后通过'element.getAttribute(“class”)''检查它的类属性。 – Arran