c# - OpenQA.Selenium.InvalidSelectorException:'无效的选择器:在 Selenium 中指定了无效或非法的选择器错误
问题描述
我在 CS 中使用 chromedriver 使用 css 选择器查找元素但是我收到以下错误:
OpenQA.Selenium.InvalidSelectorException: 'invalid selector: An invalid or illegal selector was specified
我的代码:
var body = driver.FindElementsByCssSelector(".add-to-cart.float-right.font-montserratSemiBold.text-11.lg:text-12.text-secondary.flex.flex-wrap.leading-articlesmall");
我正在尝试在此网站Add to basket
上找到按钮的元素
我的选择器出了什么问题,我该如何解决这个问题?
解决方案
试试这个选择器:
var body = driver.FindElementsByCssSelector(".add-to-cart");
推荐阅读
- perl - 无论偶数或奇数出现,捕获独特的部分
- javascript - 垫表中的复选框问题-Angular7
- reactjs - 无法从 React 中的子组件更改父级的状态
- wordpress - 自定义菜单栏 wordpress 以构建一页功能
- git - git tagging – 远程也使用本地标签?
- windows - LIB 命令创建 .lib
- python - 将抓取的数据另存为 CSV 文件?
- ios - 更改应用程序语言而不设置 iPhone 语言
- ruby - Netlify 安装 bibtex-ruby gem,但在脚本中要求“bibtex”失败
- python - 为什么 Django 日志记录不能与 Gunicorn 一起使用?