Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
C# ChromeDriver选择多个单词类名_C#_Selenium_Selenium Chromedriver - Fatal编程技术网

C# ChromeDriver选择多个单词类名

C# ChromeDriver选择多个单词类名,c#,selenium,selenium-chromedriver,C#,Selenium,Selenium Chromedriver,我尝试使用SelectElementByClassName访问ChromeDriver元素 driver.FindElementByClassName("ou selected"); 元素的类是:ou selected,但我无法使用此方法,因为我得到了: Compound class name not permitted exception 我不可能选择所有这些课程吗 有可能的解决办法吗 即使使用CSS选择,我也会遇到另一个错误,即“没有这样的元素” 元素存在: 它需要几毫秒才能加载,但

我尝试使用
SelectElementByClassName
访问ChromeDriver元素

driver.FindElementByClassName("ou selected");
元素的类是:
ou selected
,但我无法使用此方法,因为我得到了:

Compound class name not permitted exception
我不可能选择所有这些课程吗
有可能的解决办法吗


即使使用CSS选择,我也会遇到另一个错误,即“没有这样的元素”
元素存在:

它需要几毫秒才能加载,但我还是添加了一个超时,以确保它正确加载。不过,我还是犯了同样的错误。代码如下:

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
driver.FindElementByCssSelector(".ou.selected").SendKeys(OpenQA.Selenium.Keys.Enter);

在这种情况下,请使用
FindElementByCssSelector
,而不是
FindElementByClassName
。ByClassName,正如它所说的,不支持复合类。这就是为什么要使用CSS选择器来匹配所需的类

driver.FindElementByCssSelector(".ou.selected")
编辑 看起来您想要选择链接吗?如果是这样,那么你需要-

driver.FindElementByCssSelector("span.ou.selected > a")

不,我只是一个经验丰富的selenium用户和贡献者
:)
,我很高兴我的回答有帮助!谢谢@sircapsalot它帮助了我:)