硒-无法通过类名找到元素

靛青

我想用找到p标签class = "big-number"这是我写的代码:

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.className("big-number")));
System.out.println(driver.getTitle());
System.out.println(myDynamicElement);

这是我的输出:

[[FirefoxDriver: firefox on MAC (fed46ad4-9ca9-9344-a57a-1d336db3927c)] -> class name: big-number]

我无法识别错误,它给了我一个输出,但对我来说毫无意义。关于如何至少可以识别错误的任何提示?

我当然确定该元素存在,这是HTML代码:

    <div id="users-online-container" style="">
        <img class="big-number-icon" src="images/usersOnline.png">
        <p class="big-number">228</p>
        <p class="caption">Users Online</p>
    </div>
    <div id="users-online-loading"></div>
安德烈·埃格罗夫(Andrey Egorov)

发生TimeOutException是因为驱动程序无法在特定时间内找到元素。我认为选择器中存在问题。如果您确定该元素始终可见并且存在于页面上,请尝试下一个代码:

//Select first paragraph in div
driver.FindElement(By.CssSelector("#users-online-container .big-number"));
//if you have several p with same classes you could access any of them using index. e.g.
driver.findElements(By.CssSelector(".big-number"))[index];

选择器可以是#users-online-container .big-number.big-number两者都会起作用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章