首页 > 解决方案 > 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上找到按钮的元素

我的选择器出了什么问题,我该如何解决这个问题?

标签: c#seleniumxpathcss-selectorsinvalidselectorexception

解决方案


试试这个选择器:

var body = driver.FindElementsByCssSelector(".add-to-cart");

推荐阅读