gpt4 book ai didi

java - Selenium,Java-按类查找表(无 ID)

转载 作者:行者123 更新时间:2023-12-02 03:28:11 24 4
gpt4 key购买 nike

我有这样的东西:

  <table class="table">
<thead>
<tr>
<th>Role</th>
<th>Description</th>
<th>Access</th>
<th>Grant</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="role in roles">
<td>{{role.role_name}}</td>
<td>{{role.role_description}}</td>
<td><input type="checkbox" ng-model="role.allow_access" ng-change="updateAllow(role)" ng-disabled="!(role.grantor_allow_grant == 'Y' || haveAllAdminRoles)" ng-true-value="'Y'" ng-false-value="'N'"></td>
<td><input type="checkbox" ng-model="role.allow_grant" ng-change="updateAllow(role)" ng-disabled="!(role.grantor_allow_grant == 'Y' || haveAllAdminRoles)" ng-true-value="'Y'" ng-false-value="'N'"></td>
</tr>
</tbody>
</table>

如何使用 WebDriver 或 WebConnector 找到此表?我尝试过这样的事情:

WebElement table = driver.findElement(By.className("table"));

它不起作用,我收到错误:

org.openqa.selenium.NoSuchElementException: Unable to locate element:

感谢您的帮助。

最佳答案

这可能是由于时间问题造成的。您可以使用显式等待来等待表加载或可见

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement table = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("table")));
// or
WebElement table = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("table")));

关于java - Selenium,Java-按类查找表(无 ID),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38499774/

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