0
我们可以在我们的Selenium框架中编写一个类来识别用户传递的女巫定位器吗? 这意味着。在Selenium Java中解析web定位器
public class ResolveLocator {
static WebDriver driver;
static String uiUsernameTXT = "//input[@id='username']";
public static WebElement ResolveLocatorL(String uiElement) {
String checkLType = uiElement.toString();
WebElement returnLType = null;
switch (checkLType.charAt(0)) {
case '/': returnLType = driver.findElement(By.xpath(uiElement)); break;
case 'c': returnLType = driver.findElement(By.cssSelector(uiElement)); break;
case 'i': returnLType =driver.findElement(By.id(uiElement));; break;
case 'l': returnLType = driver.findElement(By.linkText(uiElement)); break;
}
return returnLType;
}
}
如果用户通过一个的XPath作为定位这个类必须识别并返回硒的正确的代码块。
的XPath为什么你需要这并不总是从/ –
开始?请问? –
我打算将不同的类保留为对象映射。 –