Java 获取Selenium中的Css值
我目前有一个HTML元素,如下所示Java 获取Selenium中的Css值,java,selenium,selenium-webdriver,css-selectors,Java,Selenium,Selenium Webdriver,Css Selectors,我目前有一个HTML元素,如下所示 <span class="onoffswitch-inner" id="aui_3_4_0_1_549"> ::before ::after </span> 到目前为止我试过什么 WebElement object = driver.findElement(By.Xpath("//span[@class='onoffswitch-inner']"); System.out.println(object.getCssVa
<span class="onoffswitch-inner" id="aui_3_4_0_1_549">
::before
::after
</span>
到目前为止我试过什么
WebElement object = driver.findElement(By.Xpath("//span[@class='onoffswitch-inner']");
System.out.println(object.getCssValue("content")); // It returns empty string
我做错了什么
如果我想得到文本“是”/“否”,我需要做什么
非常感谢我想您应该获取伪元素的css值:after,而不是元素本身。因此,某种程度上类似于
“//span[@class='onoffswitch-inner']::“
应该工作后,我有以下异常:org.openqa.selenium.InvalidSelectorException:无效选择器:无法找到xpath表达式为的元素//span[@class='onoffswitch-inner']::由于以下错误,after:语法错误:未能对“文档”执行“评估”:字符串“//span[@class='onoffswitch-Internal']::after”不是有效的XPath表达式。>>似乎不支持伪元素定位器webdriver@NguyenVuHoang:同样的问题,有进展吗?
WebElement object = driver.findElement(By.Xpath("//span[@class='onoffswitch-inner']");
System.out.println(object.getCssValue("content")); // It returns empty string