在硒webdriver中的css选择器元素之前找不到:: before [英] Unable to find ::before css selector element in selenium webdriver

查看:76
本文介绍了在硒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.

这篇关于在硒webdriver中的css选择器元素之前找不到:: before的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆