Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取Selenium中的Css值_Java_Selenium_Selenium Webdriver_Css Selectors - Fatal编程技术网

Java 获取Selenium中的Css值

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

我目前有一个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.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