Selenium 从WebElement获取唯一的css选择器
是否可以获得Web元素的css选择器 乙二醇Selenium 从WebElement获取唯一的css选择器,selenium,selenium-webdriver,kotlin,Selenium,Selenium Webdriver,Kotlin,是否可以获得Web元素的css选择器 乙二醇 var optionSelectors=mutableListOf() val options=selectWebElement?.findElements(By.cssSelector(“option”)).orEmpty() 用于(选项中的选项){ var optionSelector=option.getSelector() optionSelectors.add(optionSelector) } 返回JSON(选项选择者) 提前感谢您您可
var optionSelectors=mutableListOf()
val options=selectWebElement?.findElements(By.cssSelector(“option”)).orEmpty()
用于(选项中的选项){
var optionSelector=option.getSelector()
optionSelectors.add(optionSelector)
}
返回JSON(选项选择者)
提前感谢您您可以随时使用来获取属性值,如:
Field field = element.getClass().getDeclaredField("foundBy");
field.setAccessible(true);
String foundBy = field.get(element).toString();
然而,你的问题的本质有点奇怪,因为你已经找到了元素,你应该知道它的选择器,不是吗?如果您想与选项值进行交互,您可以选择具有的相关类
也要考虑,将测试逻辑与UI层
分开是最好的做法之一,您总是可以使用它来获得属性值:Field field = element.getClass().getDeclaredField("foundBy");
field.setAccessible(true);
String foundBy = field.get(element).toString();
然而,你的问题的本质有点奇怪,因为你已经找到了元素,你应该知道它的选择器,不是吗?如果您想与选项值进行交互,您可以选择具有的相关类
也要考虑,将测试逻辑与UI层
分开是最好的做法之一,谢谢。这只是一个例子。我有一个更复杂的案子;)非常感谢。这只是一个例子。我有一个更复杂的案子;)