我想用找到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>
发生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] 删除。
我来说两句