gpt4 book ai didi

c# - ChromeDriver 选择多个单词类名称

转载 作者:行者123 更新时间:2023-12-02 21:46:33 25 4
gpt4 key购买 nike

我尝试使用 SelectElementByClassName 通过 ChromeDriver 访问元素。

driver.FindElementByClassName("ou selected");

该元素的类是:ou selected 但我无法使用此方法,因为我得到:

Compound class name not permitted exception

我不可能选择所有这些类(class)吗?
有可能解决吗?


即使选择了 CSS,我也会收到另一个错误,提示“没有这样的元素”。
该元素存在:

enter image description here

它需要几毫秒来加载,但仍然所以我添加了一个超时以确保它正确加载。尽管如此,我还是遇到了同样的错误。这是代码:

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")

关于c# - ChromeDriver 选择多个单词类名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19429413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com