在硒webdriver中的css选择器元素之前找不到:: before
问题描述:
我要测试复选框处于选中状态还是未选中状态.
I want to test for checkbox checked or unchecked condition.
这是选中复选框的html代码
This is the html code for checkbox checked
<div classs="input-control checkbox">
<span class="check">
::before
</span>
</div>
::before
是CSS选择器.
当我将鼠标悬停在复选框上时,它显示为span.check::before
when i hoverover to checkbox, it shows webelement as span.check::before
但是
driver.FindElement(By.CssSelector("span.check::before"));
未找到throws元素.
throws element not found exception.
我们将不胜感激任何帮助.
Any help will be highly appreciated.
答
就我而言,我已从CSS选择器中删除了伪元素::before
,如下所示,它可以正常工作
In my case, I have removed the pseudo-element ::before
from the CSS selector as seen below and it works
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.cssSelector("span.check::before"))).build().perform();
我给了:
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.cssSelector("span.check"))).build().perform();
实际上不应该按照前面提到的那样在选择器中使用伪元素.此处和此处.
Using pseudo-elements in the selector is actually not supposed to work as mentioned here and here.