gpt4 book ai didi

firefox - By.cssSelector 的 Selenium WebDriver 问题

转载 作者:行者123 更新时间:2023-12-02 07:08:49 24 4
gpt4 key购买 nike

我有一个元素,它的 html 是这样的:

<div class="gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text">Announcements</div> 

我想检查这个元素是否存在。所以我正在做类似的事情:

WebDriver driver = new FirefoxDriver(profile);
driver.findElement(By.cssSelector(".titlePanelGrayDiagonal-Text"));

但它无法评估 CSSSelector。

连我都试过了:

By.cssSelector("gwt-Label.textNoStyle.textNoWrap.titlePanelGrayDiagonal-Text")

也试过这个:

By.cssSelector("div.textNoWrap.titlePanelGrayDiagonal-Text")

注意:titlePanelGrayDiagonal-Text 类在整个页面中仅由该元素使用。所以它是独一无二的。包含我无法使用的伪选择器。我只想用 css 类来标识。

版本:Selenium 2.9 WebDriver火狐 5.0

最佳答案

当使用 Webdriver 时,您希望使用 W3C 标准的 css 选择器,而不是像您可能习惯在 jquery 中使用的那样的 sizzle 选择器。在您的示例中,您可能希望使用:

driver.findElement(By.cssSelector("div[class='titlePanelGrayDiagonal-Text']"));

关于firefox - By.cssSelector 的 Selenium WebDriver 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076659/

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